> 1: How does the C code in a thread
> communicate to objects in C# code?

Nearly all of the semantics in C# are the same as in C/C++.  C# code can
declare static fields, which are nearly equivalent to C/C++ global
variables.

> 2: How does C# and a C thread
> share the same data structures?

That depends.  If you are using Managed C++, then you can very easily
access C# data.  (Threading is, in this case, irrelevant.)  If you are
using traditional unmanaged C/C++, then you will need to read up on
managed<-->unmanaged interop.  There are lots of good references on
this.  If you have the MSDN docs, start at the
System.Runtime.InteropServices namespace.

> 3: Then there is the question of locking mutexes
> that keep threads from accessing the same
> varaible or critical code section at the same time.

Again, it's different, depending on whether you are using managed C++ or
unmanaged C/C++.  If you are using managed C++, you can use the full
range of managed synchronization mechanisms -- System.Monitor,
System.Threading.Mutex, System.Threading.*, etc.

If you are interoperating with unmanaged C/C++, it gets harder, but not
much.  The easiest way is to decide that one side of your app will do
the locking -- for example, if your unmanaged C code needs to update the
C# UI, it can call into it, and the C# code can use Monitor.Enter to
synchronize access to the UI.  (Actually, if you are using Windows
Forms, you'll need to learn all about ISynchronizeInvoke, which is used
to marshal calls between non-UI threads and UI threads.)

-- arlie


-----Original Message-----
From: Moderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of REN
Sent: Sunday, November 02, 2003 9:32 AM
To: [EMAIL PROTECTED]
Subject: [ADVANCED-DOTNET] Threads between C# & C++ ??


I could use a bit of help with the following question - Appreciate any
and all input (sic).



1: How does the C code in a thread communicate to objects in
C# code?



Example: C# GUI code will have a VU meter object to display "incoming
audio signal strength". The value for is obtained by the thread by
averaging the incoming audio. The C/C++ thread must now tell the GUI
object to display it. How is this done in C to communicate with a C#
object?

If this were a straight C/C++ application, you would simply call the
objects set routine.

2: How does C# and a C thread share the same data structures?

Example: Much of my setup data is pretty much static, it changes very
little. Using variables like UserName, administratorName, etc. The C#
gui would read this data from an init file into a data structure like
the following psuedo code:



stuct nodeInfoType{

    char   UserName[80];

    char   adminstratorName[80];

};



struct nodeInfoType nodeInfo;





Now, since the variable UserName would be application global in scope,
it could be accessed by both the main thread, the C# code in this case,
and any other thread running in the same code/data space, my C code in
this case.

But, it is my understanding, given my limited knowledge of C#, that data
is contained in classes and methods. And, since C does not know what
classes and methods are, how can variables be shared?


3: Then there is the question of locking mutexes that keep threads from
accessing the same varaible or critical code section at the same time.



How are these mutexes declared in C# that can also be used in a C code
thread?

I have never done any C# programming before and these questions may have
very simple answers, and I hope they do.





Any books that you may recommend in this area?



Thanks very much for your time...

===================================
This list is hosted by DevelopMentorR  http://www.develop.com Some .NET
courses you may be interested in:

Guerrilla ASP.NET, 10 Nov 2003 in London and 26 Jan 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnet

Guerrilla .NET, 8 Dec 2003, in Los Angeles
http://www.develop.com/courses/gdotnet

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
Some .NET courses you may be interested in:

Guerrilla ASP.NET, 10 Nov 2003 in London and 26 Jan 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnet

Guerrilla .NET, 8 Dec 2003, in Los Angeles
http://www.develop.com/courses/gdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to