访问函数内的ThreadStart对象时出错

时间:2016-06-29 09:44:18

标签: c# winforms

我陷入了一个特殊的问题,希望得到一些帮助来解决这个问题。

我在下面有以下代码

    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;
-------------------
-----------------------
}

上述课程具有以下功能

 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();
            }
        }

整个源代码在VB中,并使用Telerik Online Tool转换为C#。

我在VB中添加原始方法以便更好地理解

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

我在C#语句中遇到错误   PlotLensProfileThread PlotRef = new PlotLensProfileThread(); 错误是 PlotLensProfileThread'是'字段',但用作“类型”

任何人都可以帮助我吗?

由于

1 个答案:

答案 0 :(得分:0)

您在类中已经定义了一个与下面相同名称的线程实例的行Thread PlotLensProfileThread = new Thread(new FrmSoftJobProcess(), .... 中出现错误

PlotLensProfileThread

在您的方法中,<div class="a"> <div class="b"> (varying content) </div> </div> 是自定义类还是其他内容?无论如何,您应该为您的线程或类型使用不同的名称。