• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 338
  • Last Modified:

C#, VS2008, threadpool & window form as custom messagebox

(a) I dislike the messagebox as it has no capability to timeout or close it remotely who open it first place. Many other are complex and make use of low level dll code
(b) I have simple custom message box MsgBox.
(c) I use Show() and Hide() to display MsgBox as necessary.
(d) I used backgroundworker thread and cannot use it because I have one elsewhere.
(e) This leave ThreadPool for do operation similar to backgroundworker.
(f) I have search for example in google and most and not successful in finding one related with window form.

Can anyone send me a link which make use of threadpool that open and close window and various useful task. perfer NET 3.5 modern code.

 
0
Richard Payne
Asked:
Richard Payne
  • 3
1 Solution
 
zadeveloperCommented:

 class Program
    {
        static void Main(string[] args)
        {
            var test = new FromsDisplayThreadExample();
            test.Start();

            Console.ReadLine();
        }
    }

    public class FromsDisplayThreadExample
    {
        private void DisplayMessages(object oParams)
        {
            var fmessage = new Form();
            fmessage.Width = 300;
            fmessage.Height = 100;

            fmessage.Text = "Message Title";

            fmessage.Show();
            Thread.Sleep(2000);
            fmessage.Close();
        }

        public void Start()
        {
            for (int i = 0; i < 20; i++)
            {
                ThreadPool.QueueUserWorkItem(DisplayMessages, i);
            }
        }
    }

Open in new window

0
 
käµfm³d 👽Commented:
Have you considered putting your custom form on a Timer that would close the form at some interval?
0
 
zadeveloperCommented:
var
 fmessage 
=
 
new
 
Form
();

            fmessage
.
Width
 
=
 
300
;

            fmessage
.
Height
 
=
 
100
;


            fmessage
.
Text
 
=
 
"Message Title"
;


            fmessage
.
Show
();

            
Thread
.
Sleep
(
2000
);

            fmessage
.
Close
();var fmessage = new Form();
            fmessage.Width = 300;
            fmessage.Height = 100;

            fmessage.Text = "Message Title";

            fmessage.Show();
            Thread.Sleep(2000);

with a call to your custom MsgBox
            fmessage.Close();

Open in new window

0
 
Richard PayneChief Technology EngineerAuthor Commented:
I notice new "var", is there website link to teach me how and when to use it......fundamental then pro and con.
Why async variable really matter?
0
 
zadeveloperCommented:
for var keyword checkout:

http://www.zadeveloper.com/Articles/25
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now