Friday, September 17, 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:



Ghost 20 Little-known practical parameters



xbox 360 Avchd



Gateway Bank of China has become the odds



Light: Cold Chain Dancer



CONVERT .flv to .wmv



Win32 does not require the release of resources



BenQ "tails" of the pain of expensive school fees of the three Active Role



Font Tools CATALOGS



rmvb to dvd



Reference Tools Shop



E-cology In The Pan Micro Series 29



Experience the wind Took the new brilliant new housekeeper brilliant new listing 2008



Premier Clocks And Alarms



Giant B & Q



Chinese version of Firefox: FIREFOX for free to watch television with



matroska VIDEO file



No comments:

Post a Comment