Hi, all
I am now using a Serial Port program written in C# like HyperTerminal to communicate with a radio baseband board. I will get desired response after sending certain data to the board.
There is a switch on the board. If I switch off it and then switch on it, a "RESET" string will be sent to the Serial Port program so that the program will refresh and initialize.
However, after about 30 times switch off/on, the time of refresh/initialize increases a lot. I have to wait for several minutes for the program to get ready.
I know to use a software repeatly will slow it down. However, 30 times is not very many.
I want to ask is there any way or method or suggestion for more efficient coding to create software which can be refreshed for many times and the waiting time is short
This is a real-time application...Maybe I should pay attention to other practical aspects
Thanks!

How to make the application run for long time?
MrZkitten
Thanks Mark Rendle
You show me one direction.
I will check the source code to say whether there is such situation.
Thanks!
Osiris43
When a program which does something repeatedly slows down, it is often because it is not freeing resources efficiently each time "round the loop". Make sure that all objects which implement IDisposable (e.g. Streams, Graphics) are created in using statements, so they are disposed immediately when no longer needed. Also, if any of your own classes use unmanaged resources such as COM objects, make sure they correctly implement IDisposable.
Kevin8264
If you are using classes that implementing the IDisposable interface, allways call dispose!
For your own object you can implement the IDisposable interface to release allocated unmanaged resources.
Use GC.Collect to force the garbage collection, you can specify the generation.
Use GC.WaitForPenidingFinalizers to suspend the current thread until the thread processing the queue of finalizers had emptied the queue.
But as many said before, normally you don't need this only for you own or existing objects that have unmanaged resources that should be released.
Why do you want this Normally tracking memory-leaks and disposing unmanaged resources when it isn't need is enough and you can trust on the Garbage Collector.
You can frees all substructures pointed by a unamanged memory block with Marshal.DestroyStructure or for unmanaged COM tasks memory you use Marshal.FreeCoTaskMem. Releasing COM Objects can be done with by decrementing a reference count with Marshal.ReleaseComObject and with the Marshal.Release.
But this is only needed when you are working with COM or other unmanaged objects.
Normally you implement the IDisposable interface and release everything there. When a existing object implements the IDisposable interface you can trust this and have to call it when you don't need the object any more.
enric vives
I geus it is on your code, can you show us the relevant code that reads from the Serial Post
You can allways use a profiler to trackle the bottleneck, a free profiler is Nprof, nice, free and easy.
When you want a full profiler with just some extra compared to Nprof i suggest ANTS Profiler.
Here is a full list of available tools:
IB00
Thanks for your detailed help!
I am working on someother's program now and want to solve this problem...
I will check one by one and learn related knowledge at the same time.
Thanks again!