我想将 Property 类解析为callback
方法,这样我就可以指定完成后应该执行的操作callback
。
// I have a webservice proxy created , in that webservice there is a method called Test which returns an integer value.
Myserver.servic service = new Myserver.servic() ;
// In here i am calling Test webmethod asyncronously
public void test(ccc sk , int id )
{
service.TestCompleted -= testCompleted;
service.TestCompleted += testCompleted;
//When I am caling the TestAsyn method I am parsing Guid.NewGuid()
//Because I call the same method many times simultaneously.
service.TestAsync(Guid.NewGuid ());
//But this is not how i want to call it
//I meant i want to parse some additional data to Callback method.
//In socket we can do it using AsyncState , but in WebService we cann't use UserState to parse custom data
//Because we have to parse a Guid object to it, otherwise it will generate the following error message
//Error: **There was an error during asynchronous processing. Unique state object is required for multiple asynchronous simultaneous.**
// Inorder to prevent getting this error, I have to parse new guid object as UserState
// But I also need to parse some data to Callback method
// Smething like this
//I.e
MyClass m = new MyClass () ;
m.s = "Hello" ;
m.i = 292;
m.enable = true ;
service.TestAsyn(m) ; // I want to parse data this way
// But if I parse data to call back method this way I will get that error again
// Can someone please help me ?
}
// When Call back completed I want to use something like following
public void TestCompleted(object sender, AsyncCompletedEventArgs e)
{
if (e.Error != null)
MessageBox.Show(e.Error.ToString());
if (e.Error == null)
{
MyClass m = (MyClass )e.UserState;
MessageBox.Show(m.s);
}
}
}