473,785 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multi-Threading: Accessing Main Thread Objects

I've read some documentation about accessing objects created in other
threads and the code below is similar to what I've gathered for what I have
to do:

private delegate void SetCursorCallBa ck(Cursor cursor);

// - Checks to see if the current thread is the creator of the current Form.
If the form was
// created on another thread, call Invoke so the delegate is ran in the
creating thread.
private void SetCursor(Curso r cursor)
{
if (this.InvokeReq uired()) {
SetCursorCallBa ck callBack = new SetCursorCallBa ck(SetCursor);
Invoke(callBack , cursor);
} else {
this.Cursor = cursor;
}
}

// This event gets fired in the secondary thread (not the thread that
created the form).
private void SomeVarName_Som eEventFiredFrom AnotherThread(
object sender,
EventArgs e
)
{
SetCursor(Curso rs.Default);
}

The comments in the code above are for YOUR consumption, this isn't exactly
what I have as I have snipped quite a bit of the custom code that is
irrelevant.

Is there a less-involved way to accomplish setting the properties of an
object created in a thread other than the current thread? If not, I can do
this fine, and I understand it, just wondering :)

Thanks,
Mythran

Jun 27 '08 #1
5 2268
// here could be any thread
this.Invoke((Me thodInvoker) delegate
{ // this bit runs on the UI thread
this.Cursor = Cursors.Default ;
});

Marc
Jun 27 '08 #2
On Thu, 26 Jun 2008 15:36:43 -0700, Mythran <My*****@commun ity.nospam>
wrote:
[...]
Is there a less-involved way to accomplish setting the properties of an
object created in a thread other than the current thread? If not, I can
do this fine, and I understand it, just wondering :)
Please see:
http://groups.google.com/group/micro...6c7700d2cf8a1/

We just had this discussion. :)

Pete
Jun 27 '08 #3
Thanks Marc and Pete for your excellent replies!

Hi Mythran,

Your code to handle the cross-thread operation is correct. But if you want
a convenient way to do that, as Marc and Pete have suggested, you can use
anonymous method and MethodInvoker to do it.

For example:

private void SetCursor(Curso r cursor)
{
this.Invoke((Me thodInvoker)del egate { this.Cursor = cursor; });

}

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 27 '08 #4
Ok, perhaps i'm going a little bit of topic with my next question... but I
didn't find a appropiate group to post this question and since everyone here
knows a bit of everything perhaps I could get an answer.

Basically what I need if to build a homeserver, well.. at least, set it up,
cause I have 3 computers that I could clusterize ,even though a friend told
me that clusterizing migh not be the best idea form what i have in mind,
which is hosting a website/blog and file server, and the idea is that these
3 computers share one single harddrive.

Which SO would be appropiate to do this (ok, it's pretty obvious that
windows server would be an obvious suggestion, but i can't afford it right
now) perhaps a linux distro? is clusterizing a good idea for this? or
perhaps set it up as some kind of distributed database?

Jun 29 '08 #5
On Sun, 29 Jun 2008 09:31:30 -0700, Benjamin Vigneaux <be**@mi.clwrot e:
Ok, perhaps i'm going a little bit of topic with my next question... but
I didn't find a appropiate group to post this question and since
everyone here knows a bit of everything perhaps I could get an answer.
You are off topic and the question appears to have nothing at all to do
with C# or .NET. I am positive that there is a better newsgroup for the
question. Not just so that we keep this newsgroup's signal-to-noise ratio
high, but especially so you can get useful answers to your question.

However well-informed we may be (and you may be overly optimistic on that
point), there's no way we can provide the sort of detailed information a
newsgroup actually on-topic for your question could do for you.

Pete
Jun 30 '08 #6

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

Similar topics

4
4677
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
12
3880
by: * ProteanThread * | last post by:
but depends upon the clique: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=954drf%24oca%241%40agate.berkeley.edu&rnum=2&prev=/groups%3Fq%3D%2522cross%2Bposting%2Bversus%2Bmulti%2Bposting%2522%26ie%3DUTF-8%26oe%3DUTF-8%26hl%3Den ...
0
3789
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black and white CCITT4 compressed files (frames) inside the tiff. Every now and then I receive a mixture of black and white CCITT4 and JPEG compressed files, and sometimes just multi-page tiffs with JPEG only. The code runs great when dealing with the...
6
8183
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
6
4897
by: Joe | last post by:
I have 2 multi-list boxes, 1 displays course categories based on a table called CATEGORIES. This table has 2 fields CATEGORY_ID, CATEGORY_NAME The other multi-list box displays courses based on a table called COURSES. This table has 2 fields CATEGORY_ID, COURSE_NAME. The CATEGORY_ID is a FK in COURSES and a PK in CATEGORIES. I want to populate the course list box based on any category(s)
4
17878
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the problem is the charset? How I can avoid this warning? But the worst thing isn't the warning, but that the program doesn't work! The program execute all other operations well, but it don't print the converted letters: for example, in the string...
5
6000
by: Shane Story | last post by:
I can seem to get the dimensions of a frame in a multiframe tiff. After selecting activeframe, the Width/Height is still really much larger than the page's actual dimensions. When I split a TIFF to several PNG files this causes a problem, becuase the resulting image is (the page to the far left and a lot of black space surrounding it and a filesize that is larger than needed. Any ideas?
5
5768
by: bobwansink | last post by:
Hi, I'm relatively new to programming and I would like to create a C++ multi user program. It's for a project for school. This means I will have to write a paper about the theory too. Does anyone know a good place to start looking for some theory on the subject of multi user applications? I know only bits and pieces, like about transactions, but a compendium of possible approches to multi user programming would be very appreciated!
0
2329
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing Systems (MuCoCoS'08) Barcelona, Spain, March 4 - 7, 2008; in conjunction with CISIS'08. <http://www.par.univie.ac.at/~pllana/mucocos08> *********************************************************************** Context
1
9320
by: mknoll217 | last post by:
I am recieving this error from my code: The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "PAR.PAR_Status" could not be bound. The multi-part identifier "Salary.New_Salary" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part...
0
9646
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10346
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.