Click here to Skip to main content
16,004,806 members
Home / Discussions / C#
   

C#

 
GeneralRe: DataTable output to string with filter Pin
Blubbo20-Apr-15 1:52
Blubbo20-Apr-15 1:52 
GeneralRe: DataTable output to string with filter Pin
Sascha Lefèvre20-Apr-15 1:57
professionalSascha Lefèvre20-Apr-15 1:57 
QuestionTime delay without freezing the GUI Pin
Member 1085025317-Apr-15 5:24
Member 1085025317-Apr-15 5:24 
AnswerRe: Time delay without freezing the GUI Pin
OriginalGriff17-Apr-15 5:46
mveOriginalGriff17-Apr-15 5:46 
GeneralRe: Time delay without freezing the GUI Pin
PIEBALDconsult17-Apr-15 6:46
mvePIEBALDconsult17-Apr-15 6:46 
GeneralRe: Time delay without freezing the GUI Pin
Member 1085025317-Apr-15 7:03
Member 1085025317-Apr-15 7:03 
GeneralRe: Time delay without freezing the GUI Pin
Sascha Lefèvre17-Apr-15 7:37
professionalSascha Lefèvre17-Apr-15 7:37 
GeneralRe: Time delay without freezing the GUI Pin
Eddy Vluggen17-Apr-15 8:23
professionalEddy Vluggen17-Apr-15 8:23 
Member 10850253 wrote:
How would I use a background worker to do the delay?
You start the worker from the pool, have it wait, then raise an event on the UI-thread again. Aw, yes, examples can help Smile | :)
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var f = new Form1())
                f.ShowDialog();
        }
    }
    class Form1 : Form
    {
        public Form1()
        {
            var b = new Button() { Dock = DockStyle.Fill, Text = "click" };
            b.Click += b_Click;
            Controls.Add(b);
        }

        void b_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Timer starts after this box is gone");
            ThreadPool.QueueUserWorkItem(threadMethod, null);
        }

        void threadMethod(object o)
        {
            Thread.Sleep(400);
            MethodToExecuteWhenTimeIsDone();
        }

        void MethodToExecuteWhenTimeIsDone()
        {
            if (InvokeRequired)
            {
                Invoke(new Action(MethodToExecuteWhenTimeIsDone));
                return;
            }

            this.Text = "done";
        }
    }
}
Don't mind the way the form is being built; it doesn't matter for the example. It uses the ThreadPool[^] to get a background-thread. Once you work with threads, some special rules apply, like not touching the stuff from other threads. This way you can update the UI when the thread is done, without getting cross-thread exceptions.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

AnswerRe: Time delay without freezing the GUI Pin
Richard MacCutchan17-Apr-15 5:46
mveRichard MacCutchan17-Apr-15 5:46 
QuestionLock client application (controlled) on call for Form Pin
Member 998884817-Apr-15 4:03
Member 998884817-Apr-15 4:03 
AnswerRe: Lock client application (controlled) on call for Form Pin
Dave Kreskowiak17-Apr-15 4:11
mveDave Kreskowiak17-Apr-15 4:11 
GeneralRe: Lock client application (controlled) on call for Form Pin
Member 998884817-Apr-15 4:19
Member 998884817-Apr-15 4:19 
GeneralRe: Lock client application (controlled) on call for Form Pin
Dave Kreskowiak17-Apr-15 4:24
mveDave Kreskowiak17-Apr-15 4:24 
QuestionHow to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]' Pin
Member 1099471216-Apr-15 22:42
Member 1099471216-Apr-15 22:42 
AnswerRe: How to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]' Pin
OriginalGriff16-Apr-15 23:16
mveOriginalGriff16-Apr-15 23:16 
GeneralRe: How to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]' Pin
Member 1099471216-Apr-15 23:29
Member 1099471216-Apr-15 23:29 
GeneralRe: How to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]' Pin
Pete O'Hanlon16-Apr-15 23:40
mvePete O'Hanlon16-Apr-15 23:40 
GeneralRe: How to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]' Pin
OriginalGriff16-Apr-15 23:43
mveOriginalGriff16-Apr-15 23:43 
GeneralRe: How to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]' Pin
Pete O'Hanlon16-Apr-15 23:54
mvePete O'Hanlon16-Apr-15 23:54 
GeneralRe: How to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]' Pin
Member 1099471217-Apr-15 0:36
Member 1099471217-Apr-15 0:36 
GeneralRe: How to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]' Pin
Pete O'Hanlon17-Apr-15 0:41
mvePete O'Hanlon17-Apr-15 0:41 
GeneralRe: How to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]' Pin
OriginalGriff17-Apr-15 0:47
mveOriginalGriff17-Apr-15 0:47 
GeneralRe: How to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]' Pin
Pete O'Hanlon17-Apr-15 0:49
mvePete O'Hanlon17-Apr-15 0:49 
Questioncant see my font in my C# WinForm program after install Pin
goldsoft16-Apr-15 11:07
goldsoft16-Apr-15 11:07 
AnswerRe: cant see my font in my C# WinForm program after install Pin
Dave Kreskowiak16-Apr-15 17:27
mveDave Kreskowiak16-Apr-15 17:27 

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.