Question in C# and Assembly

S

Silent Ocean

Hi All

I have following questions regarding C# Assembly and Threading.

Let me know the precise answer or lead me to the proper materials.

1. Is memory leakeage possible in .Net Manager Code ?
2. Is memory leakage possible in .Net Unmanaged Code ?
3. How can I find the what % of memory is being used by DLL at run time ?
4. What is difference between Sunchronous processing and Async
processing in .Net ? How can I achieve it ?
5. Can any one lead me towards Multithreading GUI development in Winforms ?
6. Difference between Delegate and Event ?
7. Is there any specific Design Patterns specifically for WinForms ?

Awaiting reply

Thanks

Silent Ocean
 
K

Kevin Spencer

Hi Silent Ocean,

You ask a lot! I'll give you a few answers.
1. Is memory leakeage possible in .Net Manager Code ?

Yes. Some .Net classes are wrappers for objects that must be released. Most
of these implement the IDisposable interface. A good rule of thumb is, if a
class has a Dispose method, make sure to Dispose it.
2. Is memory leakage possible in .Net Unmanaged Code ?

Of course, and easy to accomplish, if you aren't creful.. This is one of the
reasons that Managed Code was created.

A note about memory leaks: A memory leak occurs when memory is allocated by
an application and not released prior to the application shutting down.
Memory is allocated from the Operating System, and is locked by an
application. If the app fails to release the memory prior to shutting down,
the memory becomes unusable until the machine is rebooted. The .Net platform
manages memory allocation for you, with some exceptions as noted above.
3. How can I find the what % of memory is being used by DLL at run time ?
http://msdn.microsoft.com/msdnmag/issues/03/01/NETProfilerAPI/

4. What is difference between Sunchronous processing and Async processing
in .Net ? How can I achieve it ?

Synchronous processing is sequential. A thread is a sequence of
instructions. They are synchronous because they occur in sequence, one at a
time. Multi-threading is the capability to spawn multiple independent
(asynchronous) threads. The threads execute independently, and at the same
time (sort of, more or less). Actually, the threads are not "synchronized"
in any way. So, they may execute at the same time, or they may overlap in
execution, or they may not. They are independent (hence, "asynchronous").

In fact, a computer can perform precisely one machine instruction at a
time. Multi-threading is achieved by creating a large loop in the operating
system process, which takes many side trips to perform multiple tasks, a
"slice" at a time. In the olden days, this was referred to as "time
sharing." Since computers perform instructions so quickly, it looks as if
the computer is simultaneously performing many operations at the same time.

The System.Threading namespace contains the classes you need to spawn and
manage threads. Be aware, though, that there is a level of complexity
introduced by multi-threading, which makes your job much harder to do. Once
you have a program performing multiple tasks independently, there are many
pitfalls to avoid, such as race conditions and deadlocks. For example, if
one thread is attempting to fetch a member of a Collection while another
thread is modifying the Collection, you should be able to see how this could
be a problem. Make sure and bone up on the issues before you jump into it!
5. Can any one lead me towards Multithreading GUI development in Winforms
?

I'm not even sure what that means.
6. Difference between Delegate and Event ?

An Event is a message that is sent to the operating system for broadcast to
any listeners for that Event (Event Handlers). A delegate is a reference
type that encapsulates a method, or more than one method. It is similar to a
function pointer, but is type sage, object-oriented, and secure. The
delegate definition defines a signature for the methods which that delegate
can encapsulate, or point to. EventHandler is a delegate. Delegates are used
for more than handling events, however. Since a delegate can point to any
method that matches its signature, and in fact, more than one method, a
delegate can be used as a sort of placeholder for some method that is not
defined at design time. For example, you can define a method that takes a
delegate as a parameter, and later, dynamically assign one or more methods
to that delegate when executing the method. This allows a method to perform
multiple types of operations.
7. Is there any specific Design Patterns specifically for WinForms ?

Not that I know of. However, you may find the following useful:

http://msdn.microsoft.com/library/en-us/dnpatterns/html/MSpatterns.asp?frame=true

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
The sun never sets on
the Kingdom of Heaven
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top