473,383 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Running in threads...

Ok,
If I have a process start in a thread other than the "main" of the
program, can that process call other functions that are not in its
thread without any problems? Or do I have to include those functions
in the same "thread" class?

example:
public class mythread
{
public static void thread
{
///do something here
///now call function in another class <-is this OK?
}
}

Thanks,
Trint

Nov 16 '05 #1
3 1091
Trint,

The methods do not exist on the thread itself. Rather, the thread
provides an execution context for that method. You can call ANYTHING that
you want in the thread. You can call static members, or instance members.
For instance members, you have to have a reference to the instance somehow
(there are many ways to do this).

What you need to worry about is how calling properties/fields/methods
will be affected if two or more threads are trying to access it at the same
time. Take a look at the lock statement, as it will be your primary
mechanism for ensuring that you maintain the state of the objects you call
correctly.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"trint" <tr***********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Ok,
If I have a process start in a thread other than the "main" of the
program, can that process call other functions that are not in its
thread without any problems? Or do I have to include those functions
in the same "thread" class?

example:
public class mythread
{
public static void thread
{
///do something here
///now call function in another class <-is this OK?
}
}

Thanks,
Trint

Nov 16 '05 #2
UI events should be via invoke on the UI thread.
[not exactly the original question but worth knowing]

- Colin

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uv**************@TK2MSFTNGP15.phx.gbl...
Trint,

The methods do not exist on the thread itself. Rather, the thread
provides an execution context for that method. You can call ANYTHING that
you want in the thread. You can call static members, or instance members.
For instance members, you have to have a reference to the instance somehow
(there are many ways to do this).

What you need to worry about is how calling properties/fields/methods
will be affected if two or more threads are trying to access it at the same time. Take a look at the lock statement, as it will be your primary
mechanism for ensuring that you maintain the state of the objects you call
correctly.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"trint" <tr***********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Ok,
If I have a process start in a thread other than the "main" of the
program, can that process call other functions that are not in its
thread without any problems? Or do I have to include those functions
in the same "thread" class?

example:
public class mythread
{
public static void thread
{
///do something here
///now call function in another class <-is this OK?
}
}

Thanks,
Trint


Nov 16 '05 #3
Thanks,
This app runs much better.
Trint

..Net programmer
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Larry Woods | last post by:
I have a server page that has served an HTML page with a "Cancel" button on it, BUT this server page has not completed and is running a 15-30 second process before it completes. I want the browser...
3
by: MrFile | last post by:
C#.Net question for everyone I have a class that has a method that i run async from the Form. This class has one field string called log. I need this since i have an event that can write to it...
2
by: Raed Sawalha | last post by:
Hello: I have 2 windows application 1st one is periodically writing specific data to XML file , the 2nd application has a dialog with DataGrid , the datagrid filled with information in the XML...
2
by: Jeffrey Palermo, MCAD.Net | last post by:
I have some classes that control file processing in c#. The files come from a mainframe and may take some time for each to process. I use the Threadpool to process multiple files at once. Each...
7
by: mircu | last post by:
Hello, What would be the best for implementing architecture that runs several, independent, scheduled or run by the user on demand task in the same time? Now in my program every task creates...
4
by: Senthil | last post by:
Hi.. Can anyone tell how to find the threads(name or ID) running in the background using C#. I want to find those threads and to terminate if needed. Thanks, Palani.
4
by: Bill Thorne | last post by:
We have a COM object that has been wrappered for use in .NET and which can make calls which can take a while to execute. These are mainframe integration calls that might perform a lot of data...
5
by: hmoeller | last post by:
I'm looking for a way to find a specific running thread by name. I came across the System.Diagnostics.Process.Threads collection but unfortunately, this collection holds ProcessThread objects which...
1
by: DR | last post by:
what are the memory caps for threads running as a CLR stored procedure executed by sql server 2005? is it limited by OS only or also by sql servers memory limits? e.g. lets say my clr stored...
0
by: PromisedOyster | last post by:
We are having issues with our application periodically hanging. I have a timer event already running and I would like to know the state of all the running threads (foreground and background) so...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.