Tuesday, October 19, 2010

Across threads in C # Winform control access



CAD files in the program needs to read the list of file information, it is a very time-consuming operation, so I hope through multi-threaded approach to achieve, and can be suspended at any time. Since the initial use of multiple threads, beginning with an independent thread class that return data, Thread.Join () method to wait for the thread to write data to the form after the control, no difference between the results and single-threaded; later view information through the use of MethodInvoker solve this problem, but for the concept of threading is very vague, all who experience this regard, data and other shared learning to learn.

public partial class frmMain: Form

(

private volatile bool _stoped = false;

private void btFilter_Click (object sender, EventArgs e)

(

_stoped = false;

Thread t = new Thread (new ThreadStart (StartNewThread));

t.Start ();

)

private void btStop_Click (object sender, EventArgs e)

(

_stoped = true;

)

private void GetFileSize ()

(

btFilter.Enabled = false;

using (AutoCADConnector CAD = new AutoCADConnector ())

(

foreach (ListViewItem t in lvSource.Items)

(

if (! _stoped)

(

AutoCAD.AcadDocument doc = CAD.Application.Documents.Open (t.SubItems [2]. Text, true, "");

double [] p1 = new double [] (0, 0, 0); / / upper right corner coordinates

double [] p2 = new double [] (0, 0, 0); / / lower left corner

double scale = 0; / / scaling

p1 = (double []) doc.GetVariable ("EXTMAX");

p2 = (double []) doc.GetVariable ("EXTMIN");

scale = Convert.ToDouble (doc.GetVariable ("DIMSCALE"));

double w = Math.Ceiling ((p1 [0] - p2 [0]) / scale);

double h = Math.Ceiling ((p1 [1] - p2 [1]) / scale);

doc.Close (false, "");

t.SubItems [1]. Text = string.Format ("(0) * (1) (2)", w, h, scale);

/ / LvSource.Refresh ();

/ / Thread.Sleep (100);

Application.DoEvents ();

)

else

break;

)

)

btFilter.Enabled = true;

)

private void StartNewThread ()

(

MethodInvoker me = new MethodInvoker (this.GetFileSize);

this.BeginInvoke (me);

)

)







Recommended links:



Quality control in The "Statistics" several concepts



Using VMware, Vowed To Computer "cloned A Technique"



jsp Precompilation issues



3G2 to MOV



i want to find Free cell phone look up



Articles about Graphic



ASP.NET Introduces The Underlying Working Mechanisms



Firewall And Proxy SERVERS evaluation



"The Sims 3" Fun Things Continue To Occur



RMVB To MP4



Hot PIMS And Calendars



Audio Video Tools Directory



Process



Railway



Alternative workplace quit: to a rival company to do an undercover intelligence probe



MKV To MP4



Duba over one MILLION downloads in Japan very attractive price



No comments:

Post a Comment