vb.net - Error Converting VB code to C# -


so had old vb code in winforms thought convert c# using telerik online converter.

post conversion , facing issue not gettinf resolved.

the vb code here

private sub plotlensprofilethreadfunction()     dim errorflag errorflagtype = initerrorflag()     dim inmedia graphics = me.piclensplot.creategraphics     dim plotref 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 system.threading.threadabortexception         system.threading.thread.resetabort()     end try end sub 

the converted c# code here

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

the vb class has definition of threads being used in function

public class frmsoftjobprocess     dim plotlensprofilethreaddelegate new threadstart(addressof plotlensprofilethreadfunction)     dim plotlensprofilethread new thread(plotlensprofilethreaddelegate)     dim plotlensplanthreaddelegate new threadstart(addressof plotlensplanthreadfunction)     dim plotlensplanthread new thread(plotlensplanthreaddelegate)      dim minifilename string      dim jobdata softjobdatatype     dim meridianconvex integer     dim meridianconcave integer     dim meridianedge integer     dim numberoftabs integer      dim concavepaths psmg.minifile.minifiledocument     dim convexpaths psmg.minifile.minifiledocument      dim displayplot frontendstructures.displayplottype     dim plotoptions plotoptionstype      dim withevents materialfrm frmaddmaterial     dim withevents concavetoricdesignfrm frmbcmulticurvetoricdesign     dim withevents concavespheredesignfrm frmbcmulticurvespheredesign     dim withevents designfrm frmsoftconvexdesign     dim withevents newfrm frmmarkerdefinition      dim withevents tabpagechangetracker new trackchanges 

the converted c# code is

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

now problem unable access plotlensprofilethread , inref on statement plotlensprofilethread plotref = new plotlensprofilethread(); . compiler throws error plotlensprofilethread' 'field' used 'type'

can ?

unlike vb, in c#, instance field cannot reference other instance members in it's declaration's initializer. have 4 fields in class , work-arounds have attempted digging deeper trouble. usual correct work-around call initializer method constructors. converted code (just first 4 fields of class pinpoint problem) is:

public class frmsoftjobprocess {     //use flag prevent duplicate initialization case of chained constructor calls:     private bool instancefieldsinitialized = false;      public frmsoftjobprocess()     {         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; } 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -