473,414 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Nice Threads!

XDJ
I could really use some help here...

I am using C# 2005 and have created a splash screen that runs on a seperate
thread. I can invoke the splash screen in the Main() method, but then I
can't get rid of it! I am attempting to put a line in the Form1_Load (or
maybe Form1_Shown) that calls a static method from the splash screen to close
that form. But, when I do so, it complains about an invalid cross-thread
operation. How can I get this screen to close?

Here are the relevant parts to my splash screen:

// Static Public Method to launch Splash Screen
static public void ShowSplash()
{
if (ms_frmSplash != null) return;
ms_Thread = new Thread(new ThreadStart(frmSplash.ShowForm));
ms_Thread.IsBackground = true;
ms_Thread.SetApartmentState(ApartmentState.STA);
ms_Thread.Start();
}

// Static Private Method to Display Splash Screen
static private void ShowForm()
{
ms_frmSplash = new frmSplash();
Application.Run(ms_frmSplash);
}

// Static Public Method to Close Splash Screen
static public void CloseForm()
{
if (ms_frmSplash != null) ms_frmSplash.Close();
}

Feb 2 '06 #1
2 1367
Oooh! Oooh! (Doing best Horshack impression)

Perhaps you need to do this...?

static public void CloseForm()
{
MethodInvoker closeDelegate = new
MethodInvoker(ms_frmSplash.Close);
ms_frmSplash.BeginInvoke (closeDelegate );
}

I'm guessing here....

Feb 2 '06 #2
XDJ <XD*@discussions.microsoft.com> wrote:
I could really use some help here...

I am using C# 2005 and have created a splash screen that runs on a seperate
thread. I can invoke the splash screen in the Main() method, but then I
can't get rid of it! I am attempting to put a line in the Form1_Load (or
maybe Form1_Shown) that calls a static method from the splash screen to close
that form. But, when I do so, it complains about an invalid cross-thread
operation. How can I get this screen to close?


See http://www.pobox.com/~skeet/csharp/t...winforms.shtml

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ronan Viernes | last post by:
Hi, I have created a python script (see below) to count the maximum number of threads per process (by starting new threads continuously until it breaks). ###### #testThread.py import...
0
by: Al Tobey | last post by:
I was building perl 5.8.2 on RedHat Enterprise Linux 3.0 (AS) today and noticed that it included in it's ccflags "-DTHREADS_HAVE_PIDS." I am building with -Dusethreads. With newer Linux...
6
by: m | last post by:
Hello, I have an application that processes thousands of files each day. The filenames and various related file information is retrieved, related filenames are associate and placed in a linked...
34
by: Kovan Akrei | last post by:
Hi, I would like to know how to reuse an object of a thread (if it is possible) in Csharp? I have the following program: using System; using System.Threading; using System.Collections; ...
7
by: Mr. Mountain | last post by:
In the following code I simulate work being done on different threads by sleeping a couple methods for about 40 ms. However, some of these methods that should finish in about 40 -80 ms take as long...
3
by: bygandhi | last post by:
Hi - I am writing a service which will check a process and its threads for their state ( alive or dead ). The process has 5 .net managed threads created using thread.start and each have been...
10
by: [Yosi] | last post by:
I would like to know how threads behavior in .NET . When an application create 4 threads for example start all of them, the OS task manager will execute all 4 thread in deterministic order manes,...
3
by: mjheitland | last post by:
Hi, I like to know how many threads are used by a Threading.Timer object. When I create a Threading.Timer object calling a short running method every 5 seconds I expected to have one additional...
10
by: Darian | last post by:
Is there a way to find all the thread names that are running in a project? For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and T5 are running...I want to be able to know that...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.