110,534
社区成员
发帖
与我相关
我的任务
分享
public delegate void SynchronousDelegate();
private void LoadData()
{
SynchronousDelegate synchronousDelegate=new SynchronousDelegate(Function);
AsyncCallback asyncCallback = new AsyncCallback(MyAsyncCallback);
IAsyncResult ar = synchronousDelegate.BeginInvoke(asyncCallback, synchronousDelegate); //这句出错, Specified method is not supported.
}
public void MyAsyncCallback(IAsyncResult asyncResult)
{
// Because you passed your original delegate in the asyncState parameter
// of the Begin call, you can get it back here to complete the call.
SynchronousDelegate synchronousDelegate = (SynchronousDelegate)asyncResult.AsyncState;
// Complete the call.
synchronousDelegate.EndInvoke(asyncResult);
}
public void Function()
{}
serviceSoapClient.GetDataSetToStringCompleted += new EventHandler<SilverlightApplication1.WebSevices.GetDataSetToStringCompletedEventArgs>(serviceSoapClient_GetTaskTotal);
serviceSoapClient.GetDataSetToStringAsync(className, methodName, new ArrayOfAnyType() { type });
}
private void serviceSoapClient_GetTaskTotal(object sender, WebSevices.GetDataSetToStringCompletedEventArgs e)
{
//想问一下,写在这样的回调函数里?
}
/*
* 本节, 中示例提供对 BeginInvoke() 函数, 异步调用完成后系统执行回调委托。
* 回调调用 EndInvoke() 并处理异步调用的结果。
* 如果启动异步调用线程不需要处理结果是调用此调用模式很有用。
* 异步调用完成后系统调用线程以外启动线程上调。
* 若使用此调用模式, 作为第二到最后 - BeginInvoke() 函数的参数必须传递 AsyncCallback 类型的委托。
* BeginInvoke() 还有最后参数键入 对象 到您可以将任何对象。 当它调用该对象可用于您回调函数。
* 为此参数一个重要用途是以传递用于初始化调用该委托。
* 回调函数然后使用与该委托 EndInvoke() 函数来完成调用。 此调用模式是所示。
* */
//// <summary>
/// 示例 5: 异步方法完成后执行回调
/// </summary>
public void DemoCallback()
{
MethodDelegate dlgt = new MethodDelegate (this.LongRunningMethod) ;
string s ;
int iExecThread;
// Create the callback delegate.
AsyncCallback cb = new AsyncCallback(MyAsyncCallback);
// Initiate the Asynchronous call passing in the callback delegate
// and the delegate object used to initiate the call.
IAsyncResult ar = dlgt.BeginInvoke(3000, out iExecThread, cb,dlgt);
}
public void MyAsyncCallback(IAsyncResult ar)
{
string s ;
int iExecThread ;
// Because you passed your original delegate in the asyncState parameter
// of the Begin call, you can get it back here to complete the call.
MethodDelegate dlgt = (MethodDelegate) ar.AsyncState;
// Complete the call.
s = dlgt.EndInvoke (out iExecThread, ar) ;
Console.WriteLine(string.Format ("The delegate call returned the string: "{0}", and the number {1}", s, iExecThread.ToString() ) );
}
Function//这里面怎么写
{
Function 1
Function 2
}