Ich stehe bei einem speziellen Problem fest und möchte etwas Hilfe bei der Lösung dieses Problems.Fehler beim Zugriff auf das ThreadStart-Objekt innerhalb einer Funktion
Ich habe den folgenden Code unter
public partial class FrmSoftJobProcess : Form
{
private bool InstanceFieldsInitialized = false;
public FrmSoftJobProcess()
{
InitializeComponent();
Load += FrmJobProcess_Load;
FormClosing += FrmJobProcess_FormClosing;
if (!InstanceFieldsInitialized)
{
InitializeInstanceFields();
InstanceFieldsInitialized = true;
}
}
private void InitializeInstanceFields()
{
PlotLensProfileThreadDelegate = new ThreadStart(PlotLensProfileThreadFunction);
PlotLensProfileThread = new Thread(PlotLensProfileThreadDelegate);
PlotLensPlanThreadDelegate = new ThreadStart(PlotLensPlanThreadFunction);
PlotLensPlanThread = new Thread(PlotLensPlanThreadDelegate);
}
private ThreadStart PlotLensProfileThreadDelegate;
private Thread PlotLensProfileThread;
private ThreadStart PlotLensPlanThreadDelegate;
private Thread PlotLensPlanThread;
-------------------
-----------------------
}
Die Klasse oben hat folgende Funktion
private void PlotLensProfileThreadFunction()
{
Mold_Power_Suite.Model.FrontEndStructures.ErrorFlagType ErrorFlag =FrontEndStructures. InitErrorFlag();
Graphics InMedia = this.PicLensPlot.CreateGraphics();
PlotLensProfileThread PlotRef = new PlotLensProfileThread(); // how can I access this? I cant create object as its a field.
// 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();
}
}
Der gesamte Quellcode in VB war und wurde zu C# Telerik Online Tool konvertiert.
ich die Original-Methode in VB bin Hinzufügen zum besseren Verständnis
Private Sub PlotLensPlanThreadFunction()
Dim ErrorFlag As ErrorFlagType = InitErrorFlag()
Dim InMedia As Graphics = Me.PicLensPlot.CreateGraphics
Dim PlotRef As New PlotLensPlanThread()
Try
PlotRef.ThreadInGrphRef = InMedia
PlotRef.ThreadInConcavePaths = ConcavePaths
PlotRef.ThreadInConvexPaths = ConvexPaths
PlotRef.ThreadPlotOptions = PlotOptions.PlanView
PlotRef.ThreadStepSixData = JobData.StepSixData
PlotRef.ThreadStepFourData = JobData.StepFourData
PlotRef.ErrorFlag = ErrorFlag
PlotRef.MeridianConcave = MeridianConcave
PlotRef.MeridianEdge = MeridianEdge
PlotRef.MeridianConvex = MeridianConvex
PlotRef.PlotLensPlan()
Catch ex As Exception
System.Threading.Thread.ResetAbort()
End Try
End Sub
ich Fehler in der C# Aussage bin immer PlotLensProfileThread PlotRef = new PlotLensProfileThread(); Der Fehler ist PlotLensProfileThread‘ist ein‚Feld‘, sondern wie ein verwendet‚Typ‘
Kann mir jemand helfen?
Dank
PlotLensProfileThread ist eine Variable zum Erstellen von Objekt der ThreadClass, siehe Code – Apoorv
@Apoorv, ja, es gesehen und so beantwortet. Problem: Sie haben bereits eine Thread-Instanz mit diesem Namen definiert und versuchen, denselben Namen in Ihrer Methode zu verwenden. – Rahul
Wie wird PlotRef verwendet? Die Funktion verwendet PlotRef und ich weiß, dass PlotLensProfileThread eine Variable ist. kann kein Objekt einer Variablen erzeugen. – Apoorv