Thursday, September 16, 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:



International surveys: One year loss of 10,000 practitioners in the game



Small window, Big World Comparative evaluation Pocket PC 8



Enter the name of more than 50 characters in Forum



Feature library to create instance of IDS Intrusion Analysis (2)



ps3 AVCHD



News about Audio Recorders



avi apple



video format for blackberry



Vehicles - Screen Savers Infomation



archos YOUTUBE



Wizard Chat And Instant Messaging



Using The Seven Combat The Heart Jakarta Struts



Jinshan Jinshan Nu Pi typing through repeated fake "Li Gui," poisonous pit Users



PHS delisting who IS in charge



No comments:

Post a Comment