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

C#

 
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 
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 
It looks to me like you would be better off just using a timer. But, maybe you are doing an exercise in multithreading. In which case, it doesn't look like you've created a separate thread anywhere.

Something like this might be closer to what you are trying to do:

public partial class frmWordDisplayer : Form
{
    private Thread tMyThread;
    delegate void SetlabelCallback(string cCaption);

    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;
             tMyThread.Abort();
             this.Dispose();
         }

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

    public void DisplayWord()
    {
        Show();
        tMyThread = new Thread(new ThreadStart(DisplayWordThread));
        tMyThread.Start();
    }

    private void DisplayWordThread()
    {
        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);
            SetLabelCaption(words[numberChosen].ToString());
            Thread.Sleep(1000);           
        }
    }

    private void SetLabelCaption(String cCaption)
    {
       if (this.lblDisplayWord.InvokeRequired)
		{	
			SetlabelCallback d = new SetlabelCallback(SetLabelCaption);
			this.Invoke(d, new object[] { cCaption });
		}
		else
		{
			this.lblDisplayWord.Text = cCaption;
            this.lblDisplayWord.Update();
		}
    }
}


--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters

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 
AnswerRe: changing attribute value of a property outside the class . Pin
Amar Chaudhary5-Nov-06 23:08
Amar Chaudhary5-Nov-06 23:08 
AnswerRe: changing attribute value of a property outside the class . Pin
Guffa6-Nov-06 0:58
Guffa6-Nov-06 0:58 
Questionuser control items Pin
quiteSmart5-Nov-06 21:28
quiteSmart5-Nov-06 21:28 

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.