Can you post the code for the web service class? Maybe something is wrong in there?
Allan Eagle
Posts
-
Web service instance -
TreeView Question (Folder Browser)Robert, Snap. Your way of dynamically creating the tree of course would be better ... Allan
-
TreeView Question (Folder Browser)Looks like you need a bit of recursion:-
private void Form1_Load(object sender, System.EventArgs e) { AddDirectories(_Directory.Nodes, new DirectoryInfo("c:\\"), 1); } private void AddDirectories(TreeNodeCollection tn, DirectoryInfo dir, int level) { if (level <= 5) { try { DirectoryInfo[] dirs = dir.GetDirectories(); foreach(DirectoryInfo subDir in dirs) { TreeNode newNode = tn.Add(x.ToString()); newNode.Tag = subDir; AddDirectories(newNode.Nodes, subDir, level + 1); } } catch { // You may want to do something here if an error occurs } } }
The AddDirectories() method calls itself passing in DirectoryInfo and the new node for each new directory it finds and so on. The level variable in this example serves as a way to restrict how far into the directory tree the method should go. Also I usually store the DirectoryInfo into the tag of the newly created node so I can make use of it later when the node is selected by the user. -
Multiple InstancesYou mentioned that your previous attempt didn't work. Were you using a mutex?
string uniqueid = Application.ExecutablePath.Replace(@"\", @"_"); Mutex m = new Mutex(false, uniqueid); if (m.WaitOne(1, true)) { // Application is not running so carrying on running } else { // Application is already running so end here }
-
Form and Network ListenerYes you are correct. The code is halting within Form1.Run() (called from the constructor) so execution never reaches Application.Run(new Form1()), which is the reason you never see the form open. To acheive the result you require can be acheived by running the Form1.Run() method as a seperate worker thread which can be achieved something like:-
public class Form1 : System.Windows.Forms.Form { private Thread trdTcpActivityListener = null; public Form1() { InitializeComponent(); // Initialize seperate thread and start it trdTcpActivityListener = new Thread(new ThreadStart(this.Run)); trdTcpActivityListener.Start(); // Instead of - this.Run(); } public void Run() { TcpListener tcpListener = new TcpListener(IPAddress.Any, 65000); tcpListener.Start(); while (true) { // Use .Pending() to determine if there is any connections if (tcpListener.Pending()) { Socket socketForClient = tcpListener.AcceptSocket(); socketForClient.Close(); // Maximize the form this.WindowState = FormWindowState.Maximized; } // Make sure the while loop doesn't hog the CPU Thread.Sleep(30); } } }
Now whilst the worker thread waits for a TCP connection, the main thread is allowed to continue, the constructor completes and the form opens (minimized). Ill leave it up to you to work out when you should stop the worker thread.