Click here to Skip to main content
16,003,315 members
Home / Discussions / C#
   

C#

 
GeneralRe: Convert Null db field to string Pin
Colin Angus Mackay20-Jul-07 3:16
Colin Angus Mackay20-Jul-07 3:16 
GeneralRe: Convert Null db field to string Pin
Le centriste20-Jul-07 3:56
Le centriste20-Jul-07 3:56 
GeneralRe: Convert Null db field to string Pin
m@u20-Jul-07 3:30
m@u20-Jul-07 3:30 
GeneralRe: Convert Null db field to string Pin
kallileo20-Jul-07 3:37
kallileo20-Jul-07 3:37 
QuestionLabel with control Characters Pin
imnotso#20-Jul-07 0:35
imnotso#20-Jul-07 0:35 
AnswerRe: Label with control Characters Pin
Nisha S.20-Jul-07 0:55
Nisha S.20-Jul-07 0:55 
GeneralRe: Label with control Characters Pin
imnotso#20-Jul-07 1:27
imnotso#20-Jul-07 1:27 
Questionbackground Worker Class Pin
Software_Specialist20-Jul-07 0:04
Software_Specialist20-Jul-07 0:04 
Hi all,
Well i am trying to get message over textbox which is in a loop and contains many messages. But then the problem was that my form was not responding if i switch to any other application n return back to it. So it use to hang. So some1 told me to use BackGroundWorker Class. And i did that and the below code is working absolutely fine...just hv a look below..

<br />
namespace BackgroundThread<br />
{<br />
    public partial class Form1 : Form<br />
    {<br />
        public Form1()<br />
        {<br />
            InitializeComponent();<br />
        }<br />
        private BackgroundWorker worker = null;<br />
<br />
        private void Form1_Load(object sender, EventArgs e)<br />
        {<br />
            worker = new BackgroundWorker();<br />
            worker.DoWork += new DoWorkEventHandler(worker_DoWork);<br />
            worker.RunWorkerAsync();<br />
<br />
        }<br />
<br />
        void worker_DoWork(object sender, DoWorkEventArgs e)<br />
        {<br />
            for (int i = 0; i < 100000; i++)<br />
            {<br />
                if (InvokeRequired)<br />
                    Invoke(new Change(OnChange), i);<br />
            }<br />
<br />
        private void OnChange(int i)<br />
        {<br />
            textBox1.Text += i.ToString() + ",";<br />
            Application.DoEvents();<br />
            Thread.Sleep(100);<br />
        }<br />
<br />
        private delegate void Change(int i);<br />
        <br />
    }<br />
}<br />
<br />


Now comes the problem part. Suppose now i have a button over form and after clicking that it should write messages over the text box after the aboce code finish executing. But i dont know how to include that in a thread...just have a look below...

<br />
<br />
private void startBtn_Click(Object sender, EventArgs e)<br />
{<br />
  int Count = 0;<br />
  while(true)<br />
  {<br />
     if(count > 1000)<br />
      {<br />
         break;<br />
      }<br />
<br />
    Thread.Sleep(1000);<br />
    textBox1.Text += "Message" + Environment.NewLine;<br />
    textBox1.Refresh();<br />
    count++;<br />
<br />
}<br />
<br />
The above code again makes the form not responding after i press the start button. <br />
Well i know its a threading problem and i dont have much experience in threading. <br />
<br />
Well actually the above code is just an example. My real application is different and would give message over text box from different parts of application. So how to solve this case..if there is any easy way out like to refresh the form every time...etc...<br />
<br />
Any help would be greatly appreiated..<br />
Thanks<br />
<br />
<br />

AnswerRe: background Worker Class Pin
Bijesh20-Jul-07 0:22
Bijesh20-Jul-07 0:22 
AnswerRe: background Worker Class Pin
Bekjong20-Jul-07 1:20
Bekjong20-Jul-07 1:20 
Questiondatagridview row validating Pin
JoZ CaVaLLo20-Jul-07 0:03
JoZ CaVaLLo20-Jul-07 0:03 
AnswerRe: datagridview row validating Pin
led mike20-Jul-07 7:07
led mike20-Jul-07 7:07 
QuestionDrag 'n Drop Wierd Bug Pin
Toadflakz_UK19-Jul-07 23:41
Toadflakz_UK19-Jul-07 23:41 
QuestionReload a opened form another form Pin
Nisha S.19-Jul-07 22:24
Nisha S.19-Jul-07 22:24 
AnswerRe: Reload a opened form another form Pin
Martin#19-Jul-07 22:33
Martin#19-Jul-07 22:33 
AnswerRe: Reload a opened form another form Pin
N a v a n e e t h19-Jul-07 22:35
N a v a n e e t h19-Jul-07 22:35 
GeneralRe: Reload a opened form another form Pin
Pete O'Hanlon19-Jul-07 23:13
mvePete O'Hanlon19-Jul-07 23:13 
AnswerRe: Reload a opened form another form Pin
Sathesh Sakthivel19-Jul-07 22:49
Sathesh Sakthivel19-Jul-07 22:49 
GeneralRe: Reload a opened form another form Pin
Pete O'Hanlon19-Jul-07 23:00
mvePete O'Hanlon19-Jul-07 23:00 
GeneralRe: Reload a opened form another form Pin
J4amieC20-Jul-07 0:12
J4amieC20-Jul-07 0:12 
AnswerRe: Reload a opened form another form Pin
T.EDY19-Jul-07 22:55
T.EDY19-Jul-07 22:55 
GeneralRe: Reload a opened form another form Pin
Pete O'Hanlon19-Jul-07 23:02
mvePete O'Hanlon19-Jul-07 23:02 
GeneralRe: Reload a opened form another form Pin
T.EDY19-Jul-07 23:11
T.EDY19-Jul-07 23:11 
GeneralRe: Reload a opened form another form Pin
Pete O'Hanlon19-Jul-07 23:14
mvePete O'Hanlon19-Jul-07 23:14 
GeneralRe: Reload a opened form another form Pin
Martin#19-Jul-07 23:33
Martin#19-Jul-07 23:33 

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.