| | |
how to stop methods running at the same time in a console app?
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jul 2009
Posts: 12
Reputation:
Solved Threads: 0
Hi
I have a problem with a console app. It will not run methods in sequence but rather runs them all at the same time? I have put some example code below. The problem is it will run the methods below at the same time, without waiting for the frs to finish? If I remove the foreach statement it does not help. I do not have this problem with a windows forms program, only console?
I have a problem with a console app. It will not run methods in sequence but rather runs them all at the same time? I have put some example code below. The problem is it will run the methods below at the same time, without waiting for the frs to finish? If I remove the foreach statement it does not help. I do not have this problem with a windows forms program, only console?
C# Syntax (Toggle Plain Text)
Method("string1"); Method("string2"); Method("string3"); Method("string4");
C# Syntax (Toggle Plain Text)
class Program { static void Main(string[] args) { Transfer xfer = new Transfer(); xfer.Run(); } } public class Transfer { public void Run() { List<string> myList= new List<string>(); myList.Add("string1"); myList.Add("string2"); myList.Add("string3"); myList.Add("string4"); Method(string i) { //code to do whatever } foreach(string i in myList) { Method(i); } } }
I can assure you they run sequentially and not at the same time. You also posted code that won't compile so I suspect your problem lies elsewhere. Please post your complete code so we can take a look at it.
•
•
Join Date: Jul 2009
Posts: 10
Reputation:
Solved Threads: 2
i rearrange your code and runned. As far as i know its working sequentially well.
here is the code:
here is the code:
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Transfer xfer = new Transfer(); xfer.Run(); } } public class Transfer { public void Run() { List<string> myList= new List<string>(); myList.Add("string1"); myList.Add("string2"); myList.Add("string3"); myList.Add("string4"); foreach(string i in myList) { Method(i); } } public void Method(string i) { Console.WriteLine(i); } } }
Last edited by GökhanBarış; Jul 13th, 2009 at 9:08 am.
•
•
Join Date: Jul 2009
Posts: 12
Reputation:
Solved Threads: 0
Sorry, looking deeper into the code I found that an external process (System.Diagnostic.Process) was being called and was the cause of the problem. MY apologies but thanks for all that responded. The clarification that they would run is sequence forced me to look elsewhere so it helped me greatly.
thanks
thanks
![]() |
Similar Threads
- Console App? (C#)
- console app + forms (VB.NET)
- rundll32.exe is running all the time (HJT log included) (Viruses, Spyware and other Nasties)
- Stop Getting Tricked into Running Viruses (Windows tips 'n' tweaks)
- Help make Console App Open in fullscreen. (C++)
- Running Time of Recursive calls (Computer Science)
Other Threads in the C# Forum
- Previous Thread: [C#] Can't load localized resources
- Next Thread: Object-Relational Mapping
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# c#gridviewcolumn chat check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ httpwebrequest image index input install java label list listbox listener localization mandelbrot math mouseclick mysql networking object operator path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






