Нужна помощь от C# до события делегата VB.net GetInvoctionListC#

Место общения программистов C#
Ответить
Anonymous
 Нужна помощь от C# до события делегата VB.net GetInvoctionList

Сообщение Anonymous »

Я хотел бы перевести код с C# на VB.Net. Но я не очень понимаю, что я могу сделать в этот момент. У меня есть 2 сообщения об ошибках.
"Публичное событие DisplayText As DisplayTextEvent" является событием и не может быть вызвано напрямую. Используйте оператор RaiseEvent для вызова события.
как это правильно перевести?
C#
пространство имен C.I
{

Код: Выделить всё

[Serializable]
public class DisplayTextEventArgs
{
public string Text { get; set; }
public TimeSpan Duration { get; set; }

public DisplayTextEventArgs(string text, TimeSpan duration)
{
Text = text;
Duration = duration;
}

public override string ToString()
{
return String.Format("{0}", Text);
}
}

[Serializable]
public delegate void DisplayTextEvent(DisplayTextEventArgs args);

public class CaptureInterface : MarshalByRefObject
{
public event DisplayTextEvent DisplayText;

private void SafeInvokeDisplayText(DisplayTextEventArgs displayTextEventArgs)
{
if (DisplayText == null)
return;         //No Listeners

DisplayTextEvent listener = null;
Delegate[] dels = DisplayText.GetInvocationList();

foreach (Delegate del in dels)
{
try
{
listener = (DisplayTextEvent)del;
listener.Invoke(displayTextEventArgs);
}
catch (Exception)
{
//Could not reach the destination, so remove it
//from the list
DisplayText -= listener;
}
}
}
}
VB.Net
Пространство имен C.I

Код: Выделить всё

Public Class DisplayTextEventArgs
Public Property Text As String
Public Property Duration As TimeSpan

Public Sub New(text As String, duration As TimeSpan)
Me.Text = text
Me.Duration = duration
End Sub

Public Overrides Function ToString() As String
Return String.Format("{0}", Text)
End Function
End Class


Public Delegate Sub DisplayTextEvent(args As DisplayTextEventArgs)

Public Class CaptureInterface
Inherits MarshalByRefObject

Public Event DisplayText As DisplayTextEvent

Private Sub SafeInvokeDisplayText(displayTextEventArgs As DisplayTextEventArgs)
If DisplayText Is Nothing Then
Return ' No Listeners
End If

Dim listener As DisplayTextEvent = Nothing
Dim dels As [Delegate]() = DisplayText.GetInvocationList()

For Each del As [Delegate] In dels
Try
listener = CType(del, DisplayTextEvent)
listener.Invoke(displayTextEventArgs)
Catch ex As Exception
' Could not reach the destination, so remove it from the list
RemoveHandler DisplayText, listener
End Try
Next
End Sub

Public Sub DisplayTextProxyHandler(args As DisplayTextEventArgs)
RaiseEvent DisplayText(args)
End Sub

End Class
Конец пространства имен

Подробнее здесь: https://stackoverflow.com/questions/792 ... cationlist
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»