Visual Studio delay between multiple startup projects?

前端 未结 9 1303
暖寄归人
暖寄归人 2021-02-06 23:31

how to add some delay between startup projects in solution?

\"enter

I want Client

相关标签:
9条回答
  • 2021-02-06 23:51

    For the n-tier application I am currently working on, I combined the Mutex method suggested by Romil (slightly different code but same principle) and encapsulated it within a method with a [Conditional("DEBUG")] attribute applied (so it gets stripped out in release mode). We also surround the mutex logic with if (System.Diagnostics.Debugger.IsAttached) {...} since QA builds use Debug mode.

    We originally just used a Thread.Sleep with a wait period that worked for most developers machines, but we ran into problems because devs' computer speeds vary and as we added more and more to the server bootstrapper, we had to keep increasing the wait period.

    0 讨论(0)
  • 2021-02-06 23:53

    In case of multiple start-up projects, they are loaded in the order they are specified neither simultaneously nor randomly. enter image description here http://msdn.microsoft.com/en-us/library/09138bex(v=vs.90).aspx

    So ,may be if you specify "client" after "window service", then it may workout fine. And if you don't want to got the coded way suggested above, then (for testing only) you can manually attach the "client" process to you solution from a different solution after your desired delay. http://msdn.microsoft.com/en-us/library/c6wf8e4z(v=vs.100).aspx

    0 讨论(0)
  • 2021-02-06 23:55

    If the client needs to be started after, you need to adjust your list, as at the moment its started before!

    I would also code a "/wait" which on loading app if it finds that flag, waits for it maybe useful in use too.

    0 讨论(0)
  • 2021-02-06 23:58

    You can set the server project as the single startup project and use this macro to launch the server and the client with a delay:

    Sub DebugServerAndClientWithDelay()
        DTE.Debugger.Go(False)
        System.Threading.Thread.Sleep(2000)
        DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
        DTE.ActiveWindow.Object.GetItem("SolutionName\ClientProjectName").Select(vsUISelectionType.vsUISelectionTypeSelect)
        DTE.ExecuteCommand("ClassViewContextMenus.ClassViewProject.Debug.Startnewinstance")
    End Sub
    

    You can add a button to your toolbar or use a shortcut key to run this macro.

    0 讨论(0)
  • 2021-02-07 00:00

    Why don't you just pass an argument to the client application which sets the delay?

    static void main(string[] args)
    {
      // Sleep some time
      int delay;
      if (args.Length > 0 && int.TryParse(args, out delay))
      {
        Thread.Sleep(delay);
      }
    
      // Initialize client
    }
    

    Now you can add the delay in milliseconds to the command-line arguments for the project startup.

    I also agree that if possible, it's better to solve your problem structurally, so it doesn't matter when your client and server start.

    0 讨论(0)
  • 2021-02-07 00:02

    Just add a procedure to check whether the socket is open or not. If the socket is open continue executing your code and try checking again if the socket is not open. This way even if you start the windows service later there will be no problem.

    0 讨论(0)
提交回复
热议问题