Hello I have next problem with WCF. I generate my client proxy class with "task-based" async mode. With sync methods all works good, but when I call async method (void or not - irrelevant) and close my WPF MainWindow (through cross on title bar), window closed but process not killed. And this happen only after async calls.
i try this:
var client = new Service.ServiceClient();
await client.syncWithDevicesAsync();
client.Close();
and with 'using':
using (var client = new Service.ServiceClient())
{
await client.syncWithDevicesAsync();
}
I've seen similar questions, but I could not understand them, please explain why this is going. Thx for help.
UPD: In debug thread window I saw when I call async method, created 4 threads, but after response released only 3.. GC.Collect() in close window event not help.
UPD2: after Julian answer I try next:
private async void Button_Click(object sender, RoutedEventArgs e)
{
var proxy = new ServiceReference1.ServiceClient();
var photo = await proxy.getEmployeePhotoAsync(12);
label.Content = photo.Length; //everything is good, label show correct size. So the asynchronous method is completed?
proxy.Close();
//Environment.Exit(0); //- if uncomment window freeze forever. label nothing show.
}
and try this:
await Task.Run(async () =>
{
var photo = await proxy.getEmployeePhotoAsync(12);
Application.Current.Dispatcher.Invoke(() =>
{
label.Content = photo.Length;
});
});
UPD3: Oh..Now I am completely stuck. I download github example by Mahesh Sabnis. and the same behavior, the process hangs in task Manager after closing. Can someone tested at itself?