Click here to Skip to main content
15,867,308 members
Home / Discussions / C#
   

C#

 
QuestionRe: Draw line in RichTextBox C# Pin
jojoba20116-Sep-10 6:28
jojoba20116-Sep-10 6:28 
AnswerRe: Draw line in RichTextBox C# Pin
Luc Pattyn6-Sep-10 6:53
sitebuilderLuc Pattyn6-Sep-10 6:53 
GeneralRe: Draw line in RichTextBox C# Pin
DaveyM696-Sep-10 8:07
professionalDaveyM696-Sep-10 8:07 
AnswerRe: Draw line in RichTextBox C# Pin
Luc Pattyn6-Sep-10 8:19
sitebuilderLuc Pattyn6-Sep-10 8:19 
GeneralRe: Draw line in RichTextBox C# Pin
DaveyM696-Sep-10 8:27
professionalDaveyM696-Sep-10 8:27 
QuestionMulti-threading and function recursion with a form [modified] Pin
fdsfsa76f7sa66-Sep-10 3:11
fdsfsa76f7sa66-Sep-10 3:11 
AnswerRe: Mulit-threading and function recursion with a form Pin
Pete O'Hanlon6-Sep-10 3:23
subeditorPete O'Hanlon6-Sep-10 3:23 
GeneralRe: Mulit-threading and function recursion with a form Pin
fdsfsa76f7sa66-Sep-10 4:17
fdsfsa76f7sa66-Sep-10 4:17 
Thanks for the reply. BackgroundWorker class seems better for my situation, but I still don't really know what I'm doing. Here is what I tried as a test, but it gives me synchronization error.

public partial class Window : Form
{
    bool running = false;
    BackgroundWorker worker;
    int num = 0;
    public Window()
    {
        InitializeComponent();
        this.button.Click += new EventHandler(ButtonClick);
    }

    void ButtonClick(object sender, EventArgs e)
    {
        if (running)
        {
            // synchronization error here, I think it's
            // because there's no thread to pulse
            Monitor.Pulse(this);
        }
        else
        {
            running = true;
            worker = new BackgroundWorker();
            worker.DoWork += new DoWorkEventHandler(Work);
            // Work never executes w or w/o this:
            worker.RunWorkerAsync(); 
        }
    }

    void Work(object sender, DoWorkEventArgs w)
    {
        ++num;
        label.Text = num.ToString();
        Monitor.Wait(this);
        Work(null, null);
    }
}


Also, the function Work should have additional parameters, but this is not possible, because DoWork event requires only object and DoWorkEventArgs and nothing more. Would calling another function from function Work (and adding Wait statement to that function) work properly?

Thanks in advance!
GeneralRe: Mulit-threading and function recursion with a form Pin
Kubajzz6-Sep-10 4:31
Kubajzz6-Sep-10 4:31 
GeneralRe: Mulit-threading and function recursion with a form Pin
fdsfsa76f7sa66-Sep-10 5:13
fdsfsa76f7sa66-Sep-10 5:13 
GeneralRe: Mulit-threading and function recursion with a form Pin
Pete O'Hanlon6-Sep-10 4:59
subeditorPete O'Hanlon6-Sep-10 4:59 
AnswerRe: Mulit-threading and function recursion with a form Pin
Cracked-Down6-Sep-10 8:21
Cracked-Down6-Sep-10 8:21 
AnswerDammit, stop blabbing and give him the code already... Pin
lepipele7-Sep-10 4:53
lepipele7-Sep-10 4:53 
GeneralRe: Dammit, stop blabbing and give him the code already... Pin
lepipele7-Sep-10 5:10
lepipele7-Sep-10 5:10 
GeneralRe: Dammit, stop blabbing and give him the code already... Pin
fdsfsa76f7sa69-Sep-10 1:27
fdsfsa76f7sa69-Sep-10 1:27 
GeneralRe: Dammit, stop blabbing and give him the code already... Pin
lepipele9-Sep-10 6:20
lepipele9-Sep-10 6:20 
QuestionRe: Dammit, stop blabbing and give him the code already... [modified] Pin
fdsfsa76f7sa69-Sep-10 22:37
fdsfsa76f7sa69-Sep-10 22:37 
AnswerRe: Dammit, stop blabbing and give him the code already... Pin
lepipele13-Sep-10 9:30
lepipele13-Sep-10 9:30 
GeneralRe: Dammit, stop blabbing and give him the code already... Pin
fdsfsa76f7sa67-Sep-10 5:24
fdsfsa76f7sa67-Sep-10 5:24 
QuestionWindows Task Scheduler problem Pin
Tridip Bhattacharjee6-Sep-10 1:45
professionalTridip Bhattacharjee6-Sep-10 1:45 
AnswerRe: Windows Task Scheduler problem Pin
Pete O'Hanlon6-Sep-10 2:12
subeditorPete O'Hanlon6-Sep-10 2:12 
GeneralBSCS FINAL PROJECT Pin
HUSSNAIN TOUFIQ6-Sep-10 0:53
HUSSNAIN TOUFIQ6-Sep-10 0:53 
GeneralRe: BSCS FINAL PROJECT Pin
OriginalGriff6-Sep-10 0:57
mveOriginalGriff6-Sep-10 0:57 
GeneralRe: BSCS FINAL PROJECT Pin
dan!sh 6-Sep-10 0:58
professional dan!sh 6-Sep-10 0:58 
GeneralRe: BSCS FINAL PROJECT Pin
Eddy Vluggen6-Sep-10 1:14
professionalEddy Vluggen6-Sep-10 1:14 

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.