Click here to Skip to main content
14,842,359 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to access GUI from another thread? Pin
Alex Dunlop11-Feb-21 7:40
MemberAlex Dunlop11-Feb-21 7:40 
GeneralRe: How to access GUI from another thread? Pin
Alex Dunlop11-Feb-21 8:07
MemberAlex Dunlop11-Feb-21 8:07 
GeneralRe: How to access GUI from another thread? Pin
Dave Kreskowiak11-Feb-21 13:17
mveDave Kreskowiak11-Feb-21 13:17 
AnswerRe: How to access GUI from another thread? Pin
Gerry Schmitz11-Feb-21 9:03
mveGerry Schmitz11-Feb-21 9:03 
AnswerRe: How to access GUI from another thread? Pin
Ralf Meier11-Feb-21 10:36
professionalRalf Meier11-Feb-21 10:36 
AnswerRe: How to access GUI from another thread? PinPopular
Luc Pattyn11-Feb-21 11:29
sitebuilderLuc Pattyn11-Feb-21 11:29 
GeneralRe: How to access GUI from another thread? Pin
Eddy Vluggen11-Feb-21 14:01
professionalEddy Vluggen11-Feb-21 14:01 
GeneralRe: How to access GUI from another thread? Pin
Alex Dunlop11-Feb-21 18:18
MemberAlex Dunlop11-Feb-21 18:18 
I'm not wasting your time. I couldn't find out how to use the procedure in my own situation.
For example, based on the explanations in Towards Cleaner Code II, a C# GUI Invoke/Async Helper [^] I wrote the following code:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
    //button1.Text = "processing";
    if (button1.InvokeRequired)
    {
        button1.Invoke(delegate { updatetext("Processing"); });
    }
    else
    {
        updatetext("Processing");
    }

    int sum = 0;
    for (int i = 0; i <= 100; i++)
    {
        Thread.Sleep(100);
        sum = sum + i;
        backgroundWorker1.ReportProgress(i);
        if (backgroundWorker1.CancellationPending)
        {
            e.Cancel = true;
            backgroundWorker1.ReportProgress(0);
            return;
        }
    }
    e.Result = sum;
}
private void updatetext(string txt)
{
    button1.Text = txt;
}

But,
button1.Invoke(delegate { updatetext("Processing"); });
says the method is not a delegate type and cannot be compiled.

modified 12-Feb-21 0:54am.

GeneralRe: How to access GUI from another thread? Pin
Alex Dunlop11-Feb-21 19:39
MemberAlex Dunlop11-Feb-21 19:39 
GeneralRe: How to access GUI from another thread? Pin
Alex Dunlop11-Feb-21 18:16
MemberAlex Dunlop11-Feb-21 18:16 
QuestionJsonConvert.DeserializeObject Pin
Member 1449252210-Feb-21 21:43
MemberMember 1449252210-Feb-21 21:43 
AnswerRe: JsonConvert.DeserializeObject Pin
OriginalGriff10-Feb-21 22:05
mveOriginalGriff10-Feb-21 22:05 
AnswerRe: JsonConvert.DeserializeObject Pin
Member 1449252211-Feb-21 4:13
MemberMember 1449252211-Feb-21 4:13 
AnswerRe: JsonConvert.DeserializeObject Pin
James Curran11-Feb-21 23:58
MemberJames Curran11-Feb-21 23:58 
GeneralRe: JsonConvert.DeserializeObject Pin
Member 1449252212-Feb-21 7:08
MemberMember 1449252212-Feb-21 7:08 
QuestionBackGroundWorker gives runtime error Pin
Alex Dunlop10-Feb-21 4:13
MemberAlex Dunlop10-Feb-21 4:13 
AnswerRe: BackGroundWorker gives runtime error Pin
OriginalGriff10-Feb-21 4:36
mveOriginalGriff10-Feb-21 4:36 
GeneralRe: BackGroundWorker gives runtime error Pin
Alex Dunlop10-Feb-21 4:44
MemberAlex Dunlop10-Feb-21 4:44 
GeneralRe: BackGroundWorker gives runtime error Pin
OriginalGriff10-Feb-21 5:00
mveOriginalGriff10-Feb-21 5:00 
GeneralRe: BackGroundWorker gives runtime error Pin
Alex Dunlop10-Feb-21 5:03
MemberAlex Dunlop10-Feb-21 5:03 
GeneralRe: BackGroundWorker gives runtime error Pin
OriginalGriff10-Feb-21 5:43
mveOriginalGriff10-Feb-21 5:43 
GeneralRe: BackGroundWorker gives runtime error Pin
Alex Dunlop12-Feb-21 1:44
MemberAlex Dunlop12-Feb-21 1:44 
GeneralRe: BackGroundWorker gives runtime error Pin
OriginalGriff12-Feb-21 2:11
mveOriginalGriff12-Feb-21 2:11 
GeneralRe: BackGroundWorker gives runtime error Pin
Alex Dunlop12-Feb-21 6:03
MemberAlex Dunlop12-Feb-21 6:03 
AnswerRe: BackGroundWorker gives runtime error Pin
Ralf Meier10-Feb-21 4:48
professionalRalf Meier10-Feb-21 4:48 

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.