So hatte ich diesen alten VB-Code in WinForms, die ich mit Telerik Online Converter in C# konvertieren wollte.Fehler Konvertieren von VB-Code in C#
Nach der Konvertierung habe ich ein Problem, das nicht behoben wird.
Der VB-Code ist hier
Private Sub PlotLensProfileThreadFunction()
Dim ErrorFlag As ErrorFlagType = InitErrorFlag()
Dim InMedia As Graphics = Me.PicLensPlot.CreateGraphics
Dim PlotRef As New PlotLensProfileThread()
Try
PlotRef.ThreadInGrphRef = InMedia
PlotRef.ThreadInConcavePaths = ConcavePaths
PlotRef.ThreadInConvexPaths = ConvexPaths
PlotRef.ThreadPlotOptions = PlotOptions.ProfileView
PlotRef.ThreadStepSixData = JobData.StepSixData
PlotRef.ThreadStepFiveData = JobData.StepFiveData
PlotRef.ThreadStepFourData = JobData.StepFourData
PlotRef.ThreadStepThreeData = JobData.StepThreeData
PlotRef.ThreadStepTwoData = JobData.StepTwoData
PlotRef.ErrorFlag = ErrorFlag
PlotRef.MeridianConcave = MeridianConcave
PlotRef.MeridianEdge = MeridianEdge
PlotRef.MeridianConvex = MeridianConvex
ZedGraphControl1.GraphPane.CurveList.Clear()
PlotRef.zedGraphType = ZedGraphControl1
PlotRef.PlotLensProfile()
Catch e As System.Threading.ThreadAbortException
System.Threading.Thread.ResetAbort()
End Try
End Sub
Der konvertierte C# -Code ist hier
private void PlotLensProfileThreadFunction()
{
Mold_Power_Suite.Model.FrontEndStructures.ErrorFlagType ErrorFlag =FrontEndStructures. InitErrorFlag();
Graphics InMedia = this.PicLensPlot.CreateGraphics();
PlotLensProfileThread PlotRef = new PlotLensProfileThread();
// var PlotRef = PlotLensProfileThread;
try
{
PlotRef.ThreadInGrphRef = InMedia;
PlotRef.ThreadInConcavePaths = ConcavePaths;
PlotRef.ThreadInConvexPaths = ConvexPaths;
PlotRef.ThreadPlotOptions = PlotOptions.ProfileView;
PlotRef.ThreadStepSixData = JobData.StepSixData;
PlotRef.ThreadStepFiveData = JobData.StepFiveData;
PlotRef.ThreadStepFourData = JobData.StepFourData;
PlotRef.ThreadStepThreeData = JobData.StepThreeData;
PlotRef.ThreadStepTwoData = JobData.StepTwoData;
PlotRef.ErrorFlag = ErrorFlag;
PlotRef.MeridianConcave = MeridianConcave;
PlotRef.MeridianEdge = MeridianEdge;
PlotRef.MeridianConvex = MeridianConvex;
ZedGraphControl1.GraphPane.CurveList.Clear();
PlotRef.zedGraphType = ZedGraphControl1;
PlotRef.PlotLensProfile();
}
catch (System.Threading.ThreadAbortException e)
{
System.Threading.Thread.ResetAbort();
}
}
Die VB-Klasse die Definition einiger Threads hat, die in der Funktion verwendet werden
Public Class FrmSoftJobProcess
Dim PlotLensProfileThreadDelegate As New ThreadStart(AddressOf PlotLensProfileThreadFunction)
Dim PlotLensProfileThread As New Thread(PlotLensProfileThreadDelegate)
Dim PlotLensPlanThreadDelegate As New ThreadStart(AddressOf PlotLensPlanThreadFunction)
Dim PlotLensPlanThread As New Thread(PlotLensPlanThreadDelegate)
Dim MiniFilename As String
Dim JobData As SoftJobDataType
Dim MeridianConvex As Integer
Dim MeridianConcave As Integer
Dim MeridianEdge As Integer
Dim NumberOfTabs As Integer
Dim ConcavePaths As PSMG.Minifile.MinifileDocument
Dim ConvexPaths As PSMG.Minifile.MinifileDocument
Dim DisplayPlot As FrontEndStructures.DisplayPlotType
Dim PlotOptions As PlotOptionsType
Dim WithEvents MaterialFrm As FrmAddMaterial
Dim WithEvents ConcaveToricDesignFrm As frmBCMulticurveToricdesign
Dim WithEvents ConcaveSphereDesignFrm As frmBCMulticurveSphereDesign
Dim WithEvents DesignFrm As frmSoftConvexdesign
Dim WithEvents NewFrm As FrmMarkerDefinition
Dim WithEvents TabPageChangeTracker As New TrackChanges
Der konvertierte C# -Code ist
public partial class FrmSoftJobProcess : Form
{
public FrmSoftJobProcess()
{
InitializeComponent();
Load += FrmJobProcess_Load;
FormClosing += FrmJobProcess_FormClosing;
}
frmMain mainForm = new frmMain();
ThreadStart PlotLensProfileThreadDelegate = new ThreadStart(new FrmSoftJobProcess(). PlotLensProfileThreadFunction); //This has to be revisited again
Thread PlotLensProfileThread = new Thread(new FrmSoftJobProcess(). PlotLensProfileThreadDelegate);
ThreadStart PlotLensPlanThreadDelegate = new ThreadStart(new FrmSoftJobProcess().PlotLensPlanThreadFunction);
Thread PlotLensPlanThread = new Thread(new FrmSoftJobProcess().PlotLensPlanThreadDelegate);
string MiniFilename;
Mold_Power_Suite.Model.FrontEndStructures.SoftJobDataType JobData;
int MeridianConvex;
int MeridianConcave;
int MeridianEdge;
int NumberOfTabs;
PSMG.Minifile.MinifileDocument ConcavePaths;
PSMG.Minifile.MinifileDocument ConvexPaths;
FrontEndStructures.DisplayPlotType DisplayPlot;
Das Problem ist jetzt, dass ich nicht in der Lage bin PlotLensProfileThread und InRef auf dieser Aussage PlotLensProfileThread PlotRef = new PlotLensProfileThread() zuzugreifen;. Der Compiler löst den Fehler PlotLensProfileThread 'ist ein' Feld 'aber wird wie ein' Typ 'verwendet
Kann jemand helfen?
in VB.net ist der Code, ein Verfahren, mit dem ‚AddressOf‘ aufrufen, die ein Zeiger auf die Startposition von die Funktion. Es ist nicht dasselbe wie PlotLensProfileThread(), wo der Compiler in C# einen Aufruf der Methode erstellt. Siehe Webseite: http://www.codeproject.com/Articles/19911/Dynamic-Invoke-A-Method-Given-Strings-with-Met – jdweng
PlotLensProfileThread ist keine Funktion. So fett, wie ich es verstehe, ist es eine Variable, die in der ThreadStart-Klasse verwendet wird, um ein Objekt zu erzeugen. Thread PlotLensPlanThread = new Thread (new FrmSoftJobProcess(). PlotLensPlanThreadDelegate); – Apoorv
Der Vb-Code sagt: "AddressOf PlotLensProfileThreadFunction" – jdweng