Screen saver until the thread runs out

I still have a problem with the screen saver. I do not want to use the SC.TopMost=true property.

Now my application script looks like this:

in progeram.cs:

 [STAThread] static void Main() { new SplashScreen(_tempAL);// where _tempAL is an arrayList Application.Run(new Form1(_tempAL)); } 

in the SplashScreen class:

 public SplashScreen(ArrayList _Data) { DisplaySplash() } private void DisplaySplash() { this.Show(); this.TopMost = true; this.CenterToScreen(); this.SetTopLevel(true); _allServerNarrators = new string[10]; for (int i = 0; i < _allServerNarrators.Length; i++) _allServerNarrators[i] = null; GetFromServer(); this.Hide(); _serverData = new ArrayList(); _thisData.Add(_allServerNarrators); _thisData.Add(_serverNarrators); } private void GetFromServer() { _serverNarrators = new ArrayList(); string _file = "Suras.serverNar"; if (!Directory.Exists("c:\\ASGAQuraan")) Directory.CreateDirectory("c:\\ASGAQuraan"); while (counter < 4 && _serverFiles == null) { if (Download("c:\\ASGAQuraan", _ftpServerIP, _file)) { StreamReader _strReader = new StreamReader ("c:\\ASGAQuraan\\"+_file,System.Text.Encoding.Default); string _line = _strReader.ReadLine(); string _word; while (true) { while (_line != null) { _word = _line.Substring(0, _line.IndexOf("*")); int _narId = Convert.ToInt32(_word); _line = _line.Substring(2); int k = 0; _serverNarratorNode = new ArrayList(); while (true) { int ind = _line.IndexOf("*"); if (ind > 0 && ind < _line.Length) { string str = _line.Substring(0, (ind)); if (k == 0) { _allServerNarrators[_narId] = str; _serverNarratorNode.Add(str); } else { _serverNarratorNode.Add(str); } _line = _line.Substring(ind + 1); k++; } else { _line = null; break; } } _serverNarrators.Add(_serverNarratorNode); _serverFiles = "added"; } _line = _strReader.ReadLine(); if (_line == null) { break; } } } else counter++; } } 

What I want is something in the splash screen class that waits for the thread to finish.

For more information, please tell me what I need to tell you.

+20
c # winforms splash-screen
Dec 25 '08 at 15:06
source share
5 answers

After two threads a little confusing, but I'm going to take a hit and say it ...

I don’t quite understand your design here, but if the problem is that when the second application is launched, the screen saver’s screen form becomes white ... Most likely, this is due to the screen saver being filled out, running all this code in GetFromServer (). So busy that he does not have time to repaint himself.

To fix this problem, I suggest you use the BackGroundWorker component to execute the GetFromServer method. This will run this method in a separate stream and leave the stream in the form without re-drawing.

+1
Dec 25 '08 at 15:50
source share

The same question, the same answer:

The .NET framework has excellent built-in screensaver support. Launch a new WF project, Project + Add Reference, select Microsoft.VisualBasic. Add a new form, name it frmSplash. Open Project.cs and do this:

 using System; using System.Windows.Forms; using Microsoft.VisualBasic.ApplicationServices; namespace WindowsFormsApplication1 { static class Program { [STAThread] static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); new MyApp().Run(args); } } class MyApp : WindowsFormsApplicationBase { protected override void OnCreateSplashScreen() { this.SplashScreen = new frmSplash(); } protected override void OnCreateMainForm() { // Do your time consuming stuff here... //... System.Threading.Thread.Sleep(3000); // Then create the main form, the splash screen will close automatically this.MainForm = new Form1(); } } } 
+80
Dec 26 '08 at 15:11
source share

You have entered a dangerous territory by creating a user interface before calling Application.Run (). Application.Run is essentially your software message pump. By displaying the user interface before starting the application message pump, you make typical interaction with the user interface almost impossible with a premature user interface. For the splash screen, this may seem impractical, but it matters if (for example, there is a request to remove the splash screen, if it clicked, or you want to use BackgroundWorker.

This can be circumvented by creating a message pump in your splash screen (making it modal by calling ShowDialog () instead of Show ()), but that treating a symptom when dealing with a problem is really not that difficult.

I would highly recommend nobugz answer in this case. The structure provides the necessary support. Although functions in the Microsoft.VisualBasic namespace are not always available to C # programmers, they can be a real temporary resource and a lifesaver for such cases.

Good luck

+3
Dec 26 '08 at 15:34
source share

You really need to give more details about your problem. I could be completely wrong, but I will take a picture in the dark. From what I present, what happens is, and you want, you want the splash screen to display, do some processing on another thread, then the splash screen leaves when it is done.

To do this, you will need to move the GetFromServer() call to BackgroundWorker . Then move

  this.Hide(); _serverData = new ArrayList(); _thisData.Add(_allServerNarrators); _thisData.Add(_serverNarrators); 

for the BackgroundWorker_RunWorkerCompleted event handler.

To use BackgroundWorker :

1) Initialize BackgroundWorker

  BackgroundWorker myWorker = new BackgroundWorker(); 

2) Add event handlers

  myWorker.DoWork += new DoWorkEventHandler(myWorker_DoWork); //put the work you want done in this one myWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(myWorker_RunWorkerCompleted); //this gets fired when the work is finished 

3) Add code to event handlers.

4) Start myWorker.RunWorkerAsync() to get started.

As a separate note, you don't seem to be doing anything with the ArrayList that you pass to the splash screen constructor. Is this intended?

+1
Dec 25 '08 at 15:50
source share

Unfortunately, I do not have enough reputation to comment on any answer. :( This should be a response to the comment of Colonel Panic on Hans.

His problem was that the MessageBox shown with new FormMain(args) would be shown behind the splash screen. The key is to call the MessageBox from the thread behind which the splash screen starts:

 splashScreen.Invoke(new Action(() => { MessageBox.Show(splashScreen, "the message"); })); 

Where splashScreen is a reference to the splash screen object that was created in OnCreateSplashScreen and, obviously, should be assigned to the new Form1 object.

+1
Nov 26 '13 at 12:23
source share



All Articles