Click here to Skip to main content
15,925,505 members
Home / Discussions / C#
   

C#

 
AnswerRe: JIT Error Pin
Obaid ur Rehman6-Nov-06 2:49
Obaid ur Rehman6-Nov-06 2:49 
GeneralRe: JIT Error Pin
kulile6-Nov-06 3:49
kulile6-Nov-06 3:49 
Questiondrag and drop picture box [modified] Pin
rzvme6-Nov-06 1:16
rzvme6-Nov-06 1:16 
QuestionHow to implement the style of a button Pin
quiteSmart6-Nov-06 1:02
quiteSmart6-Nov-06 1:02 
AnswerRe: How to implement the style of a button Pin
Insincere Dave6-Nov-06 1:38
Insincere Dave6-Nov-06 1:38 
GeneralRe: How to implement the style of a button Pin
quiteSmart6-Nov-06 3:00
quiteSmart6-Nov-06 3:00 
GeneralRe: How to implement the style of a button Pin
Insincere Dave6-Nov-06 9:29
Insincere Dave6-Nov-06 9:29 
Questionhow to play video from stream ? Pin
hdv2126-Nov-06 0:58
hdv2126-Nov-06 0:58 
QuestionDirectShow Capture Pin
stricher_085-Nov-06 23:54
stricher_085-Nov-06 23:54 
QuestionMassive Headache with getting remainder of a sum. [modified] Pin
Gazlar835-Nov-06 23:52
Gazlar835-Nov-06 23:52 
AnswerRe: Massive Headache with getting remainder of a sum. Pin
Guffa6-Nov-06 0:55
Guffa6-Nov-06 0:55 
AnswerRe: Massive Headache with getting remainder of a sum. Pin
Luc Pattyn6-Nov-06 6:57
sitebuilderLuc Pattyn6-Nov-06 6:57 
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 
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 

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.