Click here to Skip to main content
15,886,798 members
Home / Discussions / C#
   

C#

 
Question(220v Relay), please help Pin
Muammar©5-Nov-06 23:42
Muammar©5-Nov-06 23:42 
AnswerRe: (220v Relay), please help Pin
coolestCoder5-Nov-06 23:48
coolestCoder5-Nov-06 23:48 
GeneralRe: (220v Relay), please help Pin
Muammar©7-Nov-06 20:57
Muammar©7-Nov-06 20:57 
AnswerRe: (220v Relay), please help Pin
cjengler6-Nov-06 0:06
cjengler6-Nov-06 0:06 
GeneralRe: (220v Relay), please help Pin
Muammar©7-Nov-06 20:54
Muammar©7-Nov-06 20:54 
GeneralRe: (220v Relay), please help Pin
Guffa6-Nov-06 1:15
Guffa6-Nov-06 1:15 
QuestionUse Style Builder dialog box? Pin
Gywox5-Nov-06 23:35
Gywox5-Nov-06 23:35 
Questionbackgroundworker Pin
Yustme5-Nov-06 23:24
Yustme5-Nov-06 23:24 
Hi,

A few weeks back i was trying to implement backgroundworker. I got a good code sample but i still didn't managed to get it to work.

I messed up my whole code. Nothing was working anymore. So i had to work on my backupped project. Now i got it back as how it was again.

I was kinda hoping if someone could help me again with it. Some comments would be really appreciated (in plain English).

This is my whole class:


public partial class FrmWordDisplayer : Form
{
public FrmWordDisplayer()
{
InitializeComponent();
this.FormClosing += new FormClosingEventHandler(FrmWordDisplayer_FormClosing);
}

private void FrmWordDisplayer_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult result = MessageBox.Show("wanna close?", "Conformation", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

if (result == DialogResult.Yes)
{
e.Cancel = false;
this.Dispose();
}

else if (result == DialogResult.No)
{
e.Cancel = true;
}
}

public void DisplayWord()
{
Show();
FileStream smallWords = File.Open(@"smallwords.txt", FileMode.Open, FileAccess.Read);
StreamReader rdr = new StreamReader(smallWords);
Random rnd = new Random();
string sDocument = rdr.ReadToEnd();
rdr.Close();
smallWords.Close();
string[] words = sDocument.Replace('\r', ' ').Replace('\n', ' ').Split(';');

while(true)
{
int numberChosen = rnd.Next(0, words.Length - 1);
this.lblDisplayWord.Text = words[numberChosen].ToString();
this.lblDisplayWord.Update();
Application.DoEvents();
Thread.Sleep(1000);
}
}
}

This is a second Form in my project. On my fist Form i got a few buttons. One of them, represents this Form. When this button is pressed, it execute this method: public void DisplayWord() and keeps displaying words until the user closes the Form.

But the Form still hangs. Thats why i want to implement the backgroundworker. It makes it possible the be in control of the Form the whole time.

Its this peace of code that makes the Form running slow and hang:

while(true)
{
int numberChosen = rnd.Next(0, words.Length - 1);
this.lblDisplayWord.Text = words[numberChosen].ToString();
this.lblDisplayWord.Update();
Application.DoEvents();
Thread.Sleep(1000);
}

Thanks in advance!
AnswerRe: backgroundworker Pin
mertkan656-Nov-06 4:27
mertkan656-Nov-06 4:27 
GeneralRe: backgroundworker Pin
Yustme6-Nov-06 5:11
Yustme6-Nov-06 5:11 
AnswerRe: backgroundworker Pin
Eric Dahlvang6-Nov-06 5:09
Eric Dahlvang6-Nov-06 5:09 
GeneralRe: backgroundworker Pin
Yustme6-Nov-06 10:12
Yustme6-Nov-06 10:12 
AnswerRe: backgroundworker Pin
mertkan656-Nov-06 20:46
mertkan656-Nov-06 20:46 
QuestionTravelling Salesman Problem Pin
and_reas5-Nov-06 23:14
and_reas5-Nov-06 23:14 
AnswerRe: Travelling Salesman Problem Pin
ednrgc6-Nov-06 3:52
ednrgc6-Nov-06 3:52 
AnswerCross poster not doing their own homework Pin
leckey6-Nov-06 6:44
leckey6-Nov-06 6:44 
Questionparallel cellular automata Pin
MozhdehQeraati5-Nov-06 22:54
MozhdehQeraati5-Nov-06 22:54 
QuestionExam 70–536: TS: Microsoft .NET Framework 2.0 - Application Development Foundation, Dumps? Pin
kumar.bs5-Nov-06 22:46
kumar.bs5-Nov-06 22:46 
AnswerRe: Exam 70–536: TS: Microsoft .NET Framework 2.0 - Application Development Foundation, Dumps? Pin
Tarakeshwar Reddy5-Nov-06 23:28
professionalTarakeshwar Reddy5-Nov-06 23:28 
GeneralRe: Exam 70–536: TS: Microsoft .NET Framework 2.0 - Application Development Foundation, Dumps? Pin
kumar.bs5-Nov-06 23:32
kumar.bs5-Nov-06 23:32 
AnswerRe: Exam 70–536: TS: Microsoft .NET Framework 2.0 - Application Development Foundation, Dumps? Pin
Rahithi6-Nov-06 4:21
Rahithi6-Nov-06 4:21 
QuestionDrag and drop in embedded usercontrol Pin
mesmer5-Nov-06 22:32
mesmer5-Nov-06 22:32 
Questionchanging attribute value of a property outside the class . Pin
praveenqwe5-Nov-06 22:04
praveenqwe5-Nov-06 22:04 
AnswerRe: changing attribute value of a property outside the class . Pin
quiteSmart5-Nov-06 22:36
quiteSmart5-Nov-06 22:36 
GeneralRe: changing attribute value of a property outside the class . Pin
praveenqwe5-Nov-06 22:53
praveenqwe5-Nov-06 22:53 

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.