Click here to Skip to main content
15,921,941 members
Home / Discussions / C#
   

C#

 
GeneralRe: How To Separate Number ? Pin
Vikram A Punathambekar25-Mar-08 2:47
Vikram A Punathambekar25-Mar-08 2:47 
GeneralRe: How To Separate Number ? Pin
PIEBALDconsult25-Mar-08 5:04
mvePIEBALDconsult25-Mar-08 5:04 
GeneralHelp Pin
Grim Re@p3r24-Mar-08 10:47
Grim Re@p3r24-Mar-08 10:47 
GeneralRe: Help Pin
Christian Graus24-Mar-08 10:59
protectorChristian Graus24-Mar-08 10:59 
GeneralStatusStrip does not update lable Pin
s196675m24-Mar-08 10:35
s196675m24-Mar-08 10:35 
GeneralRe: StatusStrip does not update lable Pin
CodingYoshi24-Mar-08 11:14
CodingYoshi24-Mar-08 11:14 
GeneralRe: StatusStrip does not update lable Pin
s196675m24-Mar-08 12:23
s196675m24-Mar-08 12:23 
GeneralRe: StatusStrip does not update lable Pin
CodingYoshi24-Mar-08 13:55
CodingYoshi24-Mar-08 13:55 
I am not sure where you are initiating the function from. Is it in an event handler? In any case try the following and it should work.

The idea is to create a thread and ask the thread to do some work for you--in your case do the loop. Then ever 100 iteration ask the form to update itself using a delegate.

You should improve this code as per your need but here it is anyways.

public delegate void UpdateLabel();
private Thread loopThread = null;
private string str;

private void button1_Click(object sender, EventArgs e)
{
loopThread = new Thread(new ThreadStart(DoTheLoop));
loopThread.Start();
//aThread.Join();

}

private void DoTheLoop()
{
for (int i = 1; i <= 500000; i++)
{
str = "Iteration # "; // deliberately created inside the loop
str += i.ToString();

if ((i % 100) == 0)
{
//toolStripStatusLabel1.Text = string.Empty;
//toolStripStatusLabel1.Text = str; // Update statusstrip lebel every 1000 iteration.

// Ask the form to Invoke the delegate and ask it to update the label
this.Invoke(new UpdateLabel(UpdateStatusStrip));
}

// ask the loopThread to sleep for a while so processor can do something else
Thread.Sleep(10);

}
}

private void UpdateStatusStrip()
{
toolStripStatusLabel1.Text = string.Empty;
toolStripStatusLabel1.Text = str; // Update statusstrip lebel every 1000 iteration.
}


Let me know if you have any questions.
GeneralRe: StatusStrip does not update lable Pin
s196675m24-Mar-08 14:53
s196675m24-Mar-08 14:53 
GeneralRe: StatusStrip does not update lable Pin
Luc Pattyn24-Mar-08 13:09
sitebuilderLuc Pattyn24-Mar-08 13:09 
GeneralRe: StatusStrip does not update lable Pin
s196675m24-Mar-08 14:54
s196675m24-Mar-08 14:54 
Generalreturning an XML file Pin
CodingYoshi24-Mar-08 10:26
CodingYoshi24-Mar-08 10:26 
GeneralRe: returning an XML file Pin
pmarfleet24-Mar-08 10:37
pmarfleet24-Mar-08 10:37 
GeneralRe: returning an XML file Pin
CodingYoshi24-Mar-08 10:45
CodingYoshi24-Mar-08 10:45 
GeneralRe: returning an XML file Pin
pmarfleet24-Mar-08 11:17
pmarfleet24-Mar-08 11:17 
QuestionShould I Get Visual Studio 2008? Pin
BlitzPackage24-Mar-08 9:27
BlitzPackage24-Mar-08 9:27 
AnswerRe: Should I Get Visual Studio 2008? Pin
pmarfleet24-Mar-08 9:30
pmarfleet24-Mar-08 9:30 
GeneralRe: Should I Get Visual Studio 2008? Pin
BlitzPackage24-Mar-08 9:46
BlitzPackage24-Mar-08 9:46 
GeneralRe: Should I Get Visual Studio 2008? Pin
pmarfleet24-Mar-08 10:08
pmarfleet24-Mar-08 10:08 
GeneralRe: Should I Get Visual Studio 2008? Pin
PIEBALDconsult25-Mar-08 5:07
mvePIEBALDconsult25-Mar-08 5:07 
GeneralUsing active port to send TCP packets Pin
Julinnnnnn24-Mar-08 9:09
Julinnnnnn24-Mar-08 9:09 
GeneralCreating Class library (COM object) Pin
pnpfriend24-Mar-08 8:45
pnpfriend24-Mar-08 8:45 
GeneralRe: Creating Class library (COM object) Pin
Christian Graus24-Mar-08 11:13
protectorChristian Graus24-Mar-08 11:13 
GeneralListbox not updating when items are added from another thread. Pin
Jordanwb24-Mar-08 7:49
Jordanwb24-Mar-08 7:49 
GeneralRe: Listbox not updating when items are added from another thread. Pin
ptr2void24-Mar-08 19:21
ptr2void24-Mar-08 19:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.