
qex
Avatar/Signature-
Posts
78 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by qex
-
Ok, I found most of my problem... very poor job on my part. What I did was in my printing class I created a data handler class which creates instances of other classes which access my data. Each of these data classes initializes a log class which has a timer. What I did was new() the data object then set it equal to an instance of the object I passed in to the method so I was cutting of the previous instance of the timer that I just did a new() on. So I had a bunch of timers that weren't getting disposed of. I still have some to find but my guess is its something similar. thanks guys for your help. If nothing else I learned a little bit more about GC and some of the things not to do.
-
Yeah that error is before I made a change I was worried that I was doing something incorrectly with the System.Thread which is what PrintingThread was so I changed it to use a ThreadPool instead. So to answer PrintingThread is not used at all anymore. Inside the LoadPrintRoutine I don't create any threads using threadPool or System.Thread.
-
Thats the code from printOrder()... it Writes the order to the database then spawns the thread which will open the data and print it. The thing is that error doesn't occur until the code has run about 200 times.
-
mainOrderdbf.AppendRecord() LogOrderCreatedinXFERSTAT(mainOrderdbf) OrderComplete = True OrderActive = False myPrintRoutine.ordernumber = mainOrderdbf.track '_Order_Data_0.Text 'sends the order number(tracking) to the print routine If (ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf myPrintRoutine.LoadPrintRoutine), New Object)) Then End If 'PrintingThread.Start() Dim myProgressBar1 As New ProgressBar("Printing Requisition", 500, True, "Printing... Please Wait") myProgressBar1.ShowDialog() myProgressBar1.Close() myProgressBar1.Dispose() AppConfiguration.Save2Config("OrderDbf", OrderDbf, OrderDbf.GetType) 'name of last orderfile used saved to config file
-
I did finally get something in one of my logs... I think this occurs because the system runs out of threads or thread handles... is that about right? 3/23/2006 5:14:26 PM - Exception of type 'System.OutOfMemoryException' was thrown. 3/23/2006 5:14:26 PM - at System.ModuleHandle._GetPEKind(Int32& peKind, Int32& machine) at System.ModuleHandle.GetPEKind(PortableExecutableKinds& peKind, ImageFileMachine& machine) at System.Reflection.Module.GetPEKind(PortableExecutableKinds& peKind, ImageFileMachine& machine) at System.Reflection.Assembly.ComputeProcArchIndex() at System.Reflection.Assembly.GetName(Boolean copiedName) at System.Reflection.Assembly.GetName() at System.Windows.Forms.ThreadExceptionDialog..ctor(Exception t) at System.Windows.Forms.Application.ThreadContext.OnThreadException(Exception t) at System.Windows.Forms.Control.WndProcException(Exception e) at System.Windows.Forms.Control.ControlNativeWindow.OnThreadException(Exception e) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Form.ShowDialog(IWin32Window owner) at System.Windows.Forms.Form.ShowDialog() at App.OrderEntry.printOrder(callPrintRoutine& myPrintRoutine, Thread PrintingThread) at App.OrderEntry.finishOrder()
-
Yeah, thats why I finally had to ask the question because AutomatedQA shows that there are no live(in memory) instances of my form class. Which should mean that there is not memory leak, but when I run the program and create and dispose of the form each time I do it the number of handles increases by 15-25 and the number of threads increases by 10. The numbers do not level out and eventually the application will crash with the System.outofmemory exception. I will try the CLR profiler to see if it gives me any new information As for what I'm creating the thread is used to pull together information to do a print job.
-
marble_eater thanks for the reply... Yeah I've been going through the code and have put any objects that reference the IDisposable interface in a try...catch...finally block to ensure that they are getting disposed of. Do you know for instance what type of objects would create a new thread. The only threads I explicitly create are using ThreadPool, so it must be some other interaction that is creating these threads... For example if a timer was not disposed of would that not be another thread... are there any other objects which create threads? Does creating an EventHandler create a new thread?
-
I've been chasing down memory leaks here recently and I have come to a point where I'm not sure what is causing it. I have a main form and then a child form that I create and do a showDialog() call some function is performed and then the form closes and I call Dispose(). I've found most of my memory leaks because it used to crash the system after about 25 seperate calls to this form... now it takes about 200. I've been using a Memory profiler by AutmatedQA and it says that all the Live instances of this form are gone after completion, but when I look at the task manager I see three things which may or may not be related and that is the non-paged memory keeps increasing and the number of Handles and Threads for this app keep increasing... The number of threads by about 10 each time the form is run and handles 15-25. Does anyone have any comments, suggestions, ideas. Thanks
-
Ok I figured something out. I had been using the SoapFormatter for my serialization. I found this code on the net it works as I hoped it doesn't mind if I have changed my class and added properties when it loads the data. /// <summary> /// Serializes an object instance to a file. /// </summary> /// <param name="Instance">the object instance to serialize</param> /// <param name="Filename"></param> /// <param name="BinarySerialization">determines whether XML serialization or binary serialization is used</param> /// <returns></returns> public static bool SerializeObject(object Instance, string Filename, bool BinarySerialization) { bool retVal = true; if (!BinarySerialization) { XmlTextWriter writer = null; try { XmlSerializer serializer = new XmlSerializer(Instance.GetType()); // Create an XmlTextWriter using a FileStream. Stream fs = new FileStream(Filename, FileMode.Create); writer = new XmlTextWriter(fs, new UTF8Encoding()); writer.Formatting = Formatting.Indented; writer.IndentChar = ' '; writer.Indentation = 3; // Serialize using the XmlTextWriter. serializer.Serialize(writer,Instance); } catch(Exception e) { MessageBox.Show(e.Message); retVal = false; } finally { if (writer != null) writer.Close(); } } else { Stream fs = null; try { BinaryFormatter serializer = new BinaryFormatter(); fs = new FileStream(Filename, FileMode.Create); serializer.Serialize(fs,Instance); } catch { retVal = false; } finally { if (fs != null) fs.Close(); } } return retVal; } /// <summary> /// Deserializes an object from file and returns a reference. /// </summary> /// <param name="Filename">name of the file to serialize to</param> /// <param name="ObjectType">The Type of the object. Use typeof(yourobject class)</param> /// <param name="BinarySerialization">determines whether we use Xml or Binary serialization</param> /// <returns>Instance of the deserialized object or null. Must be cast to your object type</returns> public static object DeSerializeObject(string Filename,Type ObjectType, bool BinarySerialization) { object Instance = null; if (!BinarySerialization) { XmlReader reader = null; XmlSerializer serializer = null; FileStream fs = null; try { // Create an instance of the XmlSerializer specifying type and namespace. serializer = new XmlSerializer(ObjectType); // A FileStream is needed to read the XML document. fs = new FileStream(Filename, FileMode.Open); reader = new XmlTextReader(fs); Instance = serializer.Deserialize(reader); } catch { return null; } finally { if (fs != null) fs.Close(); if (reader != null) reader.Close(); } } else { BinaryFormatter serializer = null; FileStream fs = null; try { serializer = new BinaryFormatter(); fs = new FileStream(Filename, FileMode.Open); Instance = serializer.Deserialize(fs); } catch { return null; } finally { if (fs != null) fs.Close(); } } return Instance; }
-
I have a class that I'm using for configuration of part of my app. The serializtion and deserialization work fine. The problem I'm having is if I want to add a new property to the class that is serialized then the old xml config file will not load because now the class has more members than the serialized xml file. I've found some information on the binder memeber of IFormatter class, but this seems like overkill. I would just like it to load the values that it can and then rewrite the file when I save it after the new member is added. Easier said than done?
-
Ok I figured it out. The biggest thing to remember here is that you can't count on when a thread will execute on a lock if there are possibly mutlitple threads waiting for that piece of code. But what I ended up doing was placing the data in a queue as soon as it comes in on my DataAvail event and then spinning of threads that read from the queue and by using Queue.SyncRoot to lock the usage of the Queue it keeps my Data in order... Thanks all again for your help
-
Its definitely Murphy!!! It happens at random here is the code that calls getIncomingData() My goal was to get out of here as fast as possible because while I'm in this event I'm blocking new data from being read in on my com port. Thanks for your help... I'm looking to see if maybe I can do this another way. private void ComPort_DataAvail(object sender, DataAvailEventArgs e) { try { ASCIIEncoding AE = new ASCIIEncoding(); string stringArray = ""; stringArray = AE.GetString(e.Data()); //Takes the incoming data and turns it into a string if(portStatus.postest == true) { DataCaptureArgs mypos = new DataCaptureArgs(port_settings.portID,stringArray,e.Size); OnPosTestDataAvail(mypos); } switch(CurrentState) { case CapState.start: DataTimer.Enabled = true; //Starts the timer when data stops it will fire to clean up and finish parsing ThreadPool.QueueUserWorkItem(new WaitCallback(_myParserClass.getIncomingData),stringArray); if (_createFile) { ThreadPool.QueueUserWorkItem(new WaitCallback(CreateFileThread),stringArray); } CurrentState = CapState.capturing; break; case CapState.capturing: DataTimer.Enabled = false; //data coming in so reset the timer by turning it off first ThreadPool.QueueUserWorkItem(new WaitCallback(_myParserClass.getIncomingData),stringArray); if (_createFile) { ThreadPool.QueueUserWorkItem(new WaitCallback(CreateFileThread),stringArray); } DataTimer.Enabled = true; // turn the timer back on therefor resetting the timeout to whatever the value is break; } } catch(Exception ex) { myLog.Log(string.Format("Error in DataAvail. Error: {0}",ex.Message)); myLog.Log(string.Format("Stack Trace for DataAvail Error: {0}",ex.StackTrace)); DataCaptureException ev = new DataCaptureException(ex.Message,ID); CaptureException(ev); MessageBox.Show(ex.Message); } }
-
I talked to one person and they said that Locks are not guranteed to be executed FIFO, which doesn't make sense to me. Does anyone know if this is the case for sure. So, how would I get around this. I need the data coming in to be handled in order and the whole reason that this method is in a thread and the need for the locking is that I don't want to hold up the method that is calling it. So I don't want to block the sending thread to wait for the one above because that defeats the whole purpose. Any Help?
-
I have a question about locks because I am seeing behavior that does not match what I though was the correct behavior. I thought when you put a lock around code the first instance that ran it would of course get access and then each access after that (while the first instance is still executing the code) would be essentially queued up on that lock waiting for the first to exit. But what I am seeing is that the last one there is the first to get access to the code... which doesn't make sense. If someone can shed some light I would appreciate it. Below is an example of the code and the data that it returned you can see that 4 lines that were logged before the lock and the last one was the first to go inside the lock???? 5/11/2005 11:26:43 AM - Data Before Lock: ============== 5/11/2005 11:26:43 AM - Data Before Lock: ============== 5/11/2005 11:26:43 AM - Data Before Lock: ============== 5/11/2005 11:26:43 AM - Data Before Lock: ======= DATE 5/11/2005 11:26:43 AM - Data After Lock: ======= DATE 5/11/2005 11:26:43 AM - Data Before Lock: of BIRTH: 12/ 5/11/2005 11:26:43 AM - Data After Lock: of BIRTH: 12/ 5/11/2005 11:26:43 AM - Data After Lock: ============== 5/11/2005 11:26:43 AM - Data After Lock: ============== 5/11/2005 11:26:43 AM - Data After Lock: ============== //lockingObject is a private object contained in the class with this method public void getIncomingData(object data) { try { myLog.Log(string.Format("Data Before Lock: {0}",data),true); lock(lockingObject) { myLog.Log(string.Format("Data After Lock: {0}",data),true); myParser.getIncomingData((string)data); } } catch(Exception e) { myLog.Log(string.Format("Error in DataCapture getIncomingData: {0}",e.Message)); } }
-
Thanks for your help
-
Well after a long time of looking around and just plain looking confused. This article explains the problem I was having. http://www.gotdotnet.com/team/clr/LoadFromIsolation.aspx Essentially what it was is that I referenced my Interface class at Design time and then I loaded my plugin dll at runtime from a different directory well the CLR differentiates between the two types of references especially since the one at run time was from a different directory then the exe and the statically referenced dll so they were seen as not being the same type even though they were based on the same class... Assembly a = Assembly.LoadFrom(c:\\temp\\Regcode.dll); Object o = a.CreateInstance(Regcode.UtilClass); Regcode.UtilClass x = (Regcode.UtilClass)o; //FAIL! As you can infer from this cast failure, the CLR considers the two instances of Regcode.UtilClass to be completely different types. So to fix this I had to move the plugin to the same folder as the exe so that the CLR will know they are the same base class... So that is all for my poor explanation... The article explains it pretty well.
-
I have read in several places where they say if you use BeginInvoke you should use EndInvoke as it could leak memory if you do not.
-
No, problem it's actually not a bad thing it may explain some flakey behavior that I have seen in certain circumstances... Thats what I'm hoping for at least... Thanks!
-
So what your saying is the example I gave is bad and I should not be doing that?
-
When using threads I've read in plenty of places that you are not to modify UI Controls from inside worker threads and they usualy go on to say that you should use invoke to make any changes. If I create a class and the worker thread started is given a method within that class that contains events that can be called is that the same thing or at least another way of accomplishing the same thing. For example this psuedo code example... class myClass { public myClass() { } // public void WorkerMethod() { //Do Something EventArgs e = new EventArgs(); OnSomeException(e); } public delegate void SomeErrorEventHandler(EventArgs e); public event SomeErrorEventHandler SomeException; protected virtual void OnSomeException(EventArgs e) { if(SomeException != null) { SomeException(e); } } } myClass myC = new myClass() //class declaration void main() { myC.SomeException += SomeErrorEventHandler(EventArgs e); Thread myThread = new Thread(newThreadStart(myC.WorkerMethod())); myThread.Start(); } //declare a function that will handle the SomeErrorEventHander //and modify the user interface I think this is ok since the whole point of using invoke is that the modification of the UI happens on the UI thread and thats what this accomplishes. Is this correct?
-
still having problems with this. It seems the problem is is not that createInstance fails but that I am returning the instance created and it is not able to be cast from testParser.TestParser which implements Interface.IParser to Interface.IParser. objPlugin = parserService.CreateInstance(_parser) as Interface.IParser; like I said abouve parserService.CreateInstance(_parser) returns and instance of testParser.TestParser which I'm then trying to cast to Interface.IParser. it says this cast is invalid, but I don't know why because testParser.TestParser implements Interface.IParser. Any Help will be appreciated. Thanks
-
Ok its something about the validation event that is screwing up the button click. The only thing that I can tell is that sometimes I change the text box in the validation routine, but I'm still unsure as to why then the click would not fire the button click event.
-
I'm having a problem where during the tabPage enter event I set a textbox on that tab page to have the focus. This works fine... The problem is that there are buttons on this tab page and when the textbox has focus after the enter event the first click of the button doesn't do anything other than remove the focus from the text box then it seems to work fine from that point on. The only other thing that is happening is the text box has a validation event that is firing when it loses foucs. I don't do any focusing in the validation event so does anyone have an idea of what is happening here. Thanks in advance
-
Nope that is it... just that one place.
-
any luck with this. It still doesn't make any sense. Any help with ideas about how to try to debug it or directions to take would be appreciated. Thanks for your help