0

how can I get Async call result inside getter property? my code sample is:

public  override  byte[] AddressBasedDocFile
        {
            get
            {   BaseInfoImplementationClient.AlfrescoServiceProxy.AlfrescoServicesProxyClient client = new BaseInfoImplementationClient.AlfrescoServiceProxy.AlfrescoServicesProxyClient();
                client.GetDataCompleted+=client_GetDataCompleted;
                client.GetDataAsync(this.ObjectId)  ;                       
            }
            set
            {
                base.AddressBasedDocFile = value;
            }
        }

        void client_GetDataCompleted(object sender, BaseInfoImplementationClient.AlfrescoServiceProxy.GetDataCompletedEventArgs e)
        {   
            e.Result
        }

there is a solution here that used tasks to do the job, but as I know, I can't change client.GetDataAsync(this.ObjectId) such that it returns a value, its really an asynchronous service call.

Community
  • 1
  • 1
Hamed
  • 150
  • 2
  • 16

1 Answers1

2

Properties cannot be declared asynchronous.

I recommend you should reconsider to change the getter to a async function e.g.

public async Task<bytes[]> GetAddressBasedDocFileAsync()
{
   ....
}

Getter should be fast to execute and should not throw exceptions. Performing a remote network call in a getter breaks these two best practices.

Ralf Bönning
  • 14,515
  • 5
  • 49
  • 67