Click here to Skip to main content
15,886,518 members
Home / Discussions / C#
   

C#

 
AnswerRe: Regarding the dll Pin
Vimalsoft(Pty) Ltd22-Oct-09 23:52
professionalVimalsoft(Pty) Ltd22-Oct-09 23:52 
QuestionForm Invisible and Cpu up to 50% Pin
Escocia22-Oct-09 21:51
Escocia22-Oct-09 21:51 
AnswerMessage Closed Pin
22-Oct-09 21:56
stancrm22-Oct-09 21:56 
GeneralRe: Form Invisible and Cpu up to 50% Pin
Escocia22-Oct-09 22:45
Escocia22-Oct-09 22:45 
GeneralMessage Closed Pin
22-Oct-09 23:10
stancrm22-Oct-09 23:10 
GeneralRe: Form Invisible and Cpu up to 50% Pin
Christian Graus22-Oct-09 23:25
protectorChristian Graus22-Oct-09 23:25 
AnswerRe: Form Invisible and Cpu up to 50% Pin
Christian Graus22-Oct-09 22:05
protectorChristian Graus22-Oct-09 22:05 
GeneralRe: Form Invisible and Cpu up to 50% Pin
Escocia22-Oct-09 22:57
Escocia22-Oct-09 22:57 
Hi thanks for your Answer,

I've got a FileSystemSwatcher for changes...My problem is that the form finish...Sorry, I don't think that always run..

This is recomedation of Microsoft for Invisible Forms..

To make the main form of a Windows-based application invisible when the application starts, you must move the application's startup logic into a separate class. You cannot simply set its Visible property to false.

After you have separated the lifetime of the application from the lifetime of the form, you can make forms visible (and invisible), because the application will end when you "close" the class that was used for application startup.

Note
Because a module is invisible when its code is running, the procedure that follows includes a step for adding a message box to the startup module to simply demonstrate that the application is running.


To set a form to be invisible at its inception
Do one of the following:

In Visual Basic, add a module to your Windows-based application by right-clicking the project and choosing Add Module.

In Visual C#, create a new class.

For more information about creating a Windows-based application, see How to: Create a Windows Application Project.

Within the module or class, develop a Main subroutine that can act as the startup object for the project.

The following code example shows how you might approach this.

C# Copy Code
// All methods must be contained in a class.
// This class is added to the namespace containing the Form1 class.
class MainApplication
{
public static void Main()
{
// Instantiate a new instance of Form1.
Form1 f1 = new Form1();
// Display a messagebox. This shows the application
// is running, yet there is nothing shown to the user.
// This is the point at which you customize your form.
System.Windows.Forms.MessageBox.Show("The application "
+ "is running now, but no forms have been shown.");
// Customize the form.
f1.Text = "Running Form";
// Show the instance of the form modally.
f1.ShowDialog();
}
}


Note
The message box in the previous code example is specified with a fully qualified namespace because the created module, unlike a standard Windows Form, does not import any namespaces by default. For more information about importing namespaces, see References and the Imports Statement (Visual Basic), the using Directive (C# Reference) (Visual C#), or the using Directive (C++) (Visual C++). Application.Run() will start the message pump, which is vital to the behavior of certain applications and can affect form behavior during certain times in the application lifecycle, such as on shutdown. For more information, see Application.Run Method.



My code in the new class is:

class AnotherClass
   {
       static void Main()
       {
           Form1 miF = new Form1();
           FileSystemWatcher Fs = new FileSystemWatcher();
           Fs.Created += new FileSystemEventHandler(Fs_Created);
           Fs.Path = "c:\\my";
           Fs.EnableRaisingEvents = true;
           miF.ShowInTaskbar = true;
           while (true)
           { }
       }

       static void Fs_Created(object sender, FileSystemEventArgs e)
       {
           //throw new Exception("The method or operation is not implemented.");
           FileStream Fs = File.Open("c:\\my\\probe.txt", FileMode.CreateNew);
           StreamWriter Sw = new StreamWriter(Fs);
           Sw.WriteLine(e.FullPath);
           Sw.Close();
           Fs.Close();
       }
   }


Many Thanks
GeneralRe: Form Invisible and Cpu up to 50% Pin
Christian Graus22-Oct-09 23:23
protectorChristian Graus22-Oct-09 23:23 
GeneralRe: Form Invisible and Cpu up to 50% Pin
Escocia23-Oct-09 0:06
Escocia23-Oct-09 0:06 
GeneralRe: Form Invisible and Cpu up to 50% Pin
Christian Graus23-Oct-09 0:10
protectorChristian Graus23-Oct-09 0:10 
GeneralRe: Form Invisible and Cpu up to 50% Pin
Escocia23-Oct-09 0:39
Escocia23-Oct-09 0:39 
Question[Message Deleted] Pin
sameercodes22-Oct-09 21:33
sameercodes22-Oct-09 21:33 
AnswerRe: WPF toolkit datagrid: Capture Key Press Event Pin
Christian Graus22-Oct-09 21:49
protectorChristian Graus22-Oct-09 21:49 
QuestionDistortion Metafile in Clipboard Pin
alexcmk22-Oct-09 19:18
alexcmk22-Oct-09 19:18 
AnswerRe: Distortion Metafile in Clipboard Pin
Christian Graus22-Oct-09 19:19
protectorChristian Graus22-Oct-09 19:19 
GeneralRe: Distortion Metafile in Clipboard Pin
alexcmk22-Oct-09 21:52
alexcmk22-Oct-09 21:52 
GeneralRe: Distortion Metafile in Clipboard Pin
Christian Graus22-Oct-09 22:06
protectorChristian Graus22-Oct-09 22:06 
GeneralRe: Distortion Metafile in Clipboard Pin
alexcmk26-Oct-09 14:35
alexcmk26-Oct-09 14:35 
GeneralRe: Distortion Metafile in Clipboard Pin
alexcmk27-Oct-09 15:56
alexcmk27-Oct-09 15:56 
Questionmultiple socket connection Pin
Ajithevn22-Oct-09 18:22
Ajithevn22-Oct-09 18:22 
AnswerRe: multiple socket connection Pin
Rick van Woudenberg23-Oct-09 1:07
Rick van Woudenberg23-Oct-09 1:07 
AnswerRe: multiple socket connection Pin
Jimmanuel23-Oct-09 3:16
Jimmanuel23-Oct-09 3:16 
Question[Message Deleted] Pin
Sebastian T Xavier22-Oct-09 18:05
Sebastian T Xavier22-Oct-09 18:05 
AnswerRe: Need to manipulate an excel file using MS Office SDK Pin
Christian Graus22-Oct-09 18:20
protectorChristian Graus22-Oct-09 18:20 

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.