将处理程序附加到事件:参数

时间:2011-03-07 14:39:49

标签: vb.net

我有以下代码:

AddHandler sharepoint.UploadCompleted, AddressOf UploadEmailCompleted

我要求它像这样工作:

AddHandler sharepoint.UploadCompleted, AddressOf UploadEmailCompleted(message)

我完全理解这是不可能的,经过一些研究后,我认为使用代表可能是前进的方向。但是,我正在努力实施一个有效的解决方案。

我是在正确的轨道上,还是我不能尝试的?

1 个答案:

答案 0 :(得分:1)

message的目的是什么?是发送的消息还是错误消息?如果sharepoint.UploadedCompleted返回EventArgs,则可以在回调函数中访问它们。例如,我有以下代码用于在服务中加载电子邮件模板:

Public Function LoadEmailTemplate(ByVal template As String)

    Dim path As String = AppDomain.CurrentDomain.BaseDirectory + "EmailTemplates\" + template

    Return (File.ReadAllText(path))

End Function

然后在我的客户端应用程序中,我只是这样做:

Private Sub loadEmailTemplate_completed(ByVal sender As Object, ByVal e As MainServiceReference.LoadEmailTemplateCompletedEventArgs)

    Dim body As String = e.Result
    body = body.Replace("{CHEMICAL}", chemApp.Chemical.tradeName)
    body = body.Replace("{REQUESTEDBY}", chemApp.requestedBy)
    body = body.Replace("{FACILITY}", chemApp.facilityPath)
    body = body.Replace("{ID}", chemApp.ID)



    clientMain.SendMailAsync(toAddress, fromAddress, subject, body)

End Sub

然后我可以通过LoadEmailTemplateCompletedEventArgs访问返回值。你能用sharepoint.uploadcompleted做类似的事情吗?即将其配置为返回值,然后通过EventArgs访问它?

哦,作为参考,事件处理程序只是:

AddHandler clientMain.LoadEmailTemplateCompleted, AddressOf loadEmailTemplate_completed