I've been doing all my tests in a new "test" solution right in the constructor of Form1. So its only one thread. hmmm.... I wonder if its the debugger that is causing this. I will have to test it in a Release version.
albean
Posts
-
HttpWebRequest Timeout -
HttpWebRequest TimeoutI've been doing some testing with the HttpWebRequest object returned from WebRequest.Create(sURL) method and found that the timeout property is not very precise. It often times out after more than twice the value I set. For example it takes about 30 seconds for a timeout value of 15000. I’ve seen it take 15 seconds for a value of 5000. Plus or minus a few seconds I could let slip but what might be the reason for more than doubling the timeout value? (I tested the timeout by turning the power off to my cable modem. My computer is connected to the modem through a router which I left on.)
-
Algorithm neededCP rules! Thanks guys. Your suggestions were great . . . and that set article is terrific!
-
Algorithm neededI have two sets: A{1,2,3,4,5} and B{1,3,5} I need to create set C{2,4}. Is there an optimal algorithm designed for this task? Right now I’m simply going to stick A into an array and sort it. Then I’ll iterate through each element in B and do a binary search for it in A. If not found then put it into C. Is there a better way?
-
help Me ppleaseI'm not sure if that is possible. Parse the xml file and use the YourList.Items.Add method. Also, I'm not sure what you mean by "xml file in another form". if it is some sort of object you can either make it public, make a property or create a method in the "OtherForm" that allows access to the file. Goodluck
-
getting the name of a passed parameterWhy not just pass it a collection or array that contains your "parameters".
-
Updating Listbox ItemsAre you doing something like this in your click event: MyForm f = new MyForm(); f.Show(); If you are then your problem is you are getting a NEW form each time with an empty list. Try hiding the listbox form when you are done with it. In the button click event unhide it.
-
Thread communicationYou're right, it depends on the structure of his main thread. My feeling is he would not want to block on the Monitor.Wait, though. AK, let us know what you find. You have Arun and me intrested. :)
-
Thread communicationI guess AK could use your idea and monitor from the Application.Idle event.
-
Thread communicationSounds like a good idea but I'm wondering where you would monitor it from. In AK's situation I think he is looking for an event to occur but in your situation you probably have a worker thread that is looping - before it begins another iteration you check to see if it should stop. Since there is no “loop” for AK he would need an event… I do like your approach, though, for workers.
-
MessageBoxIconDoes anybody know how I can access the MessagBoxIcons directly? I want to stick one on a Form (not a MessageBox). Is there some sort of internal imagelist in the Framework?
-
Thread communicationI had to do something similar to this but because I come from the Win32 C++ world I took an API approach so there may be a better C# way of doing this. Anyway, what I did was an override of the WndProc method on the main thread and used post message from the polling thread. As I recall I was under pressure for a fast workaround and did not have time to thoroughly research an optimal solution. I would be interested in what you come up with.
-
2 projects 1 classThanks David. That seems to do it.
-
Thread.Sleep is too slowEggie, You need to read about the Thread.Sleep method and more importantly what a context switch is. Sleep( X ) means the thread will not be scheduled for execution by the operating system for X milliseconds. Sleep(0) causes the thread to be suspended (a context switch) and immediately rescheduled for another time slice. If there are no other threads at your thread’s priority level then it is executed. The bottom line is you will not be able to create a delay to the precision you are looking for. (Well, you might be able to with in-line assembly but a context switch could occur and make the “delay” longer. And, now that I think about it, you will probably have to boost your thread’s priority. ) Sleep(0) is the shortest delay that I can think of but there is no control over its duration. Since there will be other threads waiting, they will all execute their time slices before yours gets the CPU back. I don’t recall what Microsoft has a time slice set at its probably around 50ms so if there are n threads scheduled before yours the delay will be n * ~50ms In the post above Daniel wrote “More time resolution is only available with multimedia timers or DirectX.” He is right. What I’m speaking about is similar to you listening to music or watching a dvd on your computer. If you do anything that uses the CPU a lot, the music or movie becomes "choppy." That is, indirectly, related to the context switches that I’m talking about. Besides these context switches there are other things like interrupts going on(e.g. moving the mouse). Anyway, there is always a workaround for coding problems. Good luck. BTW: You got me curious. Why do you need such a short delay for? Context switch: (this is just a summary, Google around for more details) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/context\_switches.asp Sleep Method: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemthreadingthreadclasssleeptopic1.asp
-
help Me ppleasewhat you just described is a whole program. which part are you having trouble with? Seems to me that you also need an OK button (and a cancel button). In the ok button event place the code that takes the userid and psswd and does what you need. (i.e. you time stamping, output to the xml file ...)
-
Thread.Sleep is too slowIf you just want a short "delay" then you do not want to use Thread.Sleep. Because even a Thread.Sleep(0) causes a context switch and it may take "a long time" for the OS to hand control back to your program, depending on how many threads/tasks are scheduled. Perhaps there is a way to inline some assembly in a C# app (I don't know about this though) and you could execute a no-op or something that would fill your requirements for a delay. But you will still have that context switching problem since windows is preemptive multitasking. Consider this: 1 Executing code 2 Executing code 3 Your Delay 4 Executing code 5 Executing code Even if there were some (atomic) delay statement that you could use at step 3 a context switch could take place between 3 and 4. This would make your delay appear to be even longer. Good luck though, maybe there is a workaround.
-
2 projects 1 classThanks, but Project A is not class lib (dll). Its an EXE that contains a class that I need to use in Project B.
-
2 projects 1 classI have one solution with two projects (project A & project B). Is there a way to "reference" a class in A from within B? If I'm in project B and from the solution's explorer I choose "Add Existing Item" it copies the file from A's physical directory into B's directory. I'm sorta trying to forward reference the class.
-
Thread.Sleep is too slowWhen Thread.Sleep is executed the .NET framework makes a system call that immediately causes a context switch. (AFAIK) Could you give a little more info about what you are trying to do?
-
Global Logger instanceI've always passed around a reference to an instance of a Logger in most apps that I've developed. There has to be a better way. What do you guys do? I'd like to make a single instance that can be used anywhere in the program. Should I be considering a Singleton design pattern.... ??? I don't need anything fancy. All I need to do is: MyLogger.Log("Message"); Is it possible to make an instance global to a namespace?