kaizen
Member
- Joined
- Mar 12, 2008
- Messages
- 8
- Programming Experience
- 5-10
Hi guys,
I am trying to convert some C# code into Vb.NEt and it is giving me some hassles.
The C# code is below.
Any my converted Vb.Net is below.
The code in red is the code I am not sure about. It has to do with multi threading and delegates which I am not very clued up on.
Any ideas?
Thanks
I am trying to convert some C# code into Vb.NEt and it is giving me some hassles.
The C# code is below.
VB.NET:
using System;
using System.Collections.Generic;
using System.Text;
using RightEdge.Common;
using fxClientAPI;
using System.Diagnostics;
using System.Threading;
[Serializable]
public class OrderEventHandler : fxAccountEvent
{
private OandaPlugin _plugin;
public OrderEventHandler(OandaPlugin plugin)
{
_plugin = plugin;
}
private void Handle(fxAccountEventInfo info)
{
bool matched;
OandaPlugin.PendingItem item = new OandaPlugin.PendingItem(info);
_plugin.HandleTransaction(item, out matched);
if (!matched)
{
_plugin._pendingTransactions.Add(item);
_plugin._synchContext.Post(delegate
{
_plugin.NewTick();
}, null);
}
}
public void DoEvent(fxEventInfo ei)
{
if (ei is fxAccountEventInfo)
{
fxAccountEventInfo info = (fxAccountEventInfo)ei;
string msg = "Oanda: " + info.Transaction.Description + " Trans: " + info.Transaction.TransactionNumber +
" Link: " + info.Transaction.Link + " Qty: " + info.Transaction.Units;
if (Thread.CurrentThread != _plugin.mainThread)
{
//msg = "Off main thread: " + msg;
//Trace.WriteLine(msg);
_plugin._synchContext.Post(delegate
{
Handle(info);
}, null);
}
else
{
//Trace.WriteLine(msg);
Handle(info);
}
}
else
{
if (Thread.CurrentThread != _plugin.mainThread)
{
_plugin._synchContext.Post(delegate
{
_plugin.Log("Unknown argument type for match: " + ei.GetType().ToString());
}, null);
}
else
{
_plugin.Log("Unknown argument type for match: " + ei.GetType().ToString());
}
}
}
public override bool match(fxEventInfo ei)
{
DoEvent(ei);
return base.match(ei);
}
public override void handle(fxEventInfo ei, fxEventManager em)
{
DoEvent(ei);
base.handle(ei, em);
}
}
Any my converted Vb.Net is below.
VB.NET:
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports RightEdge.Common
Imports fxClientAPI
Imports System.Diagnostics
Imports System.Threading
Public Class OrderEventHandler
Inherits fxAccountEvent
Private _plugin As OandaPlugin
Public Sub New(ByVal plugin As OandaPlugin)
_plugin = plugin
End Sub
Private Sub Handle(ByVal info As fxAccountEventInfo)
Dim matched As Boolean
Dim item As OandaPlugin.PendingItem = New OandaPlugin.PendingItem(info)
_plugin.HandleTransaction(item,out matched)
If Not matched Then
_plugin._pendingTransactions.Add(item)
[COLOR="Red"] _plugin._synchContext.Post(delegate { _plugin.NewTick()}, Nothing)[/COLOR]
End If
End Sub
Public Sub DoEvent(ByVal ei As fxEventInfo)
If TypeOf ei Is fxAccountEventInfo Then
Dim info As fxAccountEventInfo = CType(ei, fxAccountEventInfo)
Dim msg As String = "Oanda: " + info.Transaction.Description + " Trans: " + info.Transaction.TransactionNumber + _
" Link: " + info.Transaction.Link + " Qty: " + info.Transaction.Units
If [COLOR="Red"]Thread.CurrentThread <> _plugin.mainThread[/COLOR] Then
'msg = "Off main thread: " + msg;
'Trace.WriteLine(msg);
[COLOR="Red"]_plugin._synchContext.Post(delegate { Handle(info)}, Nothing)[/COLOR]
Else
'Trace.WriteLine(msg);
Handle(info)
End If
Else
If [COLOR="Red"]Thread.CurrentThread <> _plugin.mainThread[/COLOR] Then
[COLOR="Red"]_plugin._synchContext.Post(delegate {_plugin.Log("Unknown argument type for match: " + ei.GetType().ToString())}, Nothing)[/COLOR]
Else
_plugin.Log("Unknown argument type for match: " + ei.GetType().ToString())
End If
End If
End Sub
Public Overrides Function match(ByVal ei As fxEventInfo) As Boolean
DoEvent(ei)
Return MyBase.match(ei)
End Function
Public Overrides Sub handle(ByVal ei As fxEventInfo, ByVal em As fxEventManager)
DoEvent(ei)
MyBase.handle(ei, em)
End Sub
End Class
The code in red is the code I am not sure about. It has to do with multi threading and delegates which I am not very clued up on.
Any ideas?
Thanks