Multiple instances of the same Async task (Windows Phone)
Posted
by
Bart Teunissen
on Stack Overflow
See other posts from Stack Overflow
or by Bart Teunissen
Published on 2012-03-26T11:26:28Z
Indexed on
2012/03/26
11:28 UTC
Read the original article
Hit count: 180
After googeling for ages, and reading some stuff about async task in books. I made a my first program with an async task in it. Only to find out, that i can only start one task. I want to run the task more then once. This is where i found out that that doesn't seem to work. to be a little bit clearer, here are some parts of my code:
InitFunction(var);
This is the Task itself
public async Task InitFunction(string var)
{
_VarHandle = await _AdsClient.GetSymhandleByNameAsync(var);
_Data = await _AdsClient.ReadAsync<T>(_VarHandle);
_AdsClient.AddNotificationAsync<T>(_VarHandle, AdsTransmissionMode.OnChange, 1000, this);
}
This works like a charm when i execute the task only once.. But is there a possibility to run it multiple times. Something like this?
InitFunction(var1);
InitFunction(var2);
InitFunction(var3);
Because if i do this now (multiple tasks at once), the task it wants to start is still running, and it throws an exeption.
if someone could help me with this, that would be awesome!
~ Bart
© Stack Overflow or respective owner