Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use void method with Task.factory.fromAsync

I am using wcf to perform the task of insert the data. I am using one of wcf void function to insert the user data

AceVqbzServiceClient aceVqbzClientService = new AceVqbzServiceClient();
aceVqbzClientService.OpenAsync();
IAceVqbzService aceVqbzTypeService = aceVqbzClientService as IAceVqbzService;

Task.Factory.FromAsync(
            aceVqbzTypeService.BeginSaveUserOrganizationLinking,
            aceVqbzTypeService.EndSaveUserOrganizationLinking,
            objUser_OrganizationDetail, 
            TaskCreationOptions.None);

aceVqbzClientService.CloseAsync();

this is the function

Function is not giving any issue when i am using but data is not inserting through this. Please give me solution so that i can implement this

like image 635
Mukesh Kumar Avatar asked Apr 26 '26 23:04

Mukesh Kumar


1 Answers

You need the asynchronously wait (with await) the Task returned from FromAsync:

public async Task FooAsync()
{
    AceVqbzServiceClient aceVqbzClientService = new AceVqbzServiceClient();
    await aceVqbzClientService.OpenAsync();
    IAceVqbzService aceVqbzTypeService = aceVqbzClientService as IAceVqbzService;

    await Task.Factory.FromAsync(
                       aceVqbzTypeService.BeginSaveUserOrganizationLinking,
                       aceVqbzTypeService.EndSaveUserOrganizationLinking,
                       objUser_OrganizationDetail, TaskCreationOptions.None);

    await aceVqbzClientService.CloseAsync();
}
like image 93
Yuval Itzchakov Avatar answered Apr 29 '26 11:04

Yuval Itzchakov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!