473,386 Members | 1,715 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,386 software developers and data experts.

[c#-form] delegates, threads

77
Ok, I’m new to this oo stuff so it sort of confuses the hell out of me at times.. Anyway, I have my main form which contains 3 panels and the center panel gets populated with 6 user controls. So I’m told data flow can only go from the main form to the control and not visa versa. I know there’s a way for it to be done with delegates but the help I have had and the guides I have used, I just don’t understand. it seems like i’m standing in front of my goal but im going to take a 10 mile round trip just because im told to. I don’t understand why I need to do this, or how to do it.

the problem is made worse because I now need multi threading. I need the main form to kick of a function in usercontrol2 (page2) in a new thread. problem being, I need the app/user control to wait for that thread to finish before continuing. and I need another user control displayed over the top of page 2 until it’s complete.

now the only way I can see this is working is if I can check the isalive property of the thread. but I don’t know how I would repeat this to allow it to continue when done and I don’t know enough about delegates to do it. all the delegate tutorials show it done on one page of code.. which doesn’t help me at all.

I know this is quite broad but any hints, tips, reasoning and or coding would be a great help.

Thanks,
Piercy
Oct 30 '07 #1
8 1580
Shashi Sadasivan
1,435 Expert 1GB
Ok, I’m new to this oo stuff so it sort of confuses the hell out of me at times.. Anyway, I have my main form which contains 3 panels and the center panel gets populated with 6 user controls. So I’m told data flow can only go from the main form to the control and not visa versa. I know there’s a way for it to be done with delegates but the help I have had and the guides I have used, I just don’t understand. it seems like i’m standing in front of my goal but im going to take a 10 mile round trip just because im told to. I don’t understand why I need to do this, or how to do it.

the problem is made worse because I now need multi threading. I need the main form to kick of a function in usercontrol2 (page2) in a new thread. problem being, I need the app/user control to wait for that thread to finish before continuing. and I need another user control displayed over the top of page 2 until it’s complete.

now the only way I can see this is working is if I can check the isalive property of the thread. but I don’t know how I would repeat this to allow it to continue when done and I don’t know enough about delegates to do it. all the delegate tutorials show it done on one page of code.. which doesn’t help me at all.

I know this is quite broad but any hints, tips, reasoning and or coding would be a great help.

Thanks,
Piercy
Have you tried the backgroundworker component
Read up on that...its less messier to use and you can check if the thread has finished or not ans things like that
it can even report its progress.
Oct 30 '07 #2
piercy
77
unfortunatly, im having to devlop in .net 1.1 because the app im developing thid "addon" for has issues with 2.0+.

although, im now gutted because worker threads looked way easier.

Thansk again,
Oct 30 '07 #3
Plater
7,872 Expert 4TB
So what you have is a form. And with that form, you need some action to be performed in another thread. While that is going on you need the UI to show something like "Please wait..." and then remove itself when the action in the other thread is finished.
Is that right?
Now where do these user controls fit in?
What "event"(s) do you need a notice from then?
Oct 30 '07 #4
piercy
77
So what you have is a form. And with that form, you need some action to be performed in another thread. While that is going on you need the UI to show something like "Please wait..." and then remove itself when the action in the other thread is finished.
Is that right?
Now where do these user controls fit in?
What "event"(s) do you need a notice from then?

thats exactly it. user controls fit into a panel in the main form. i have several pages and the user controls just show and hide in the panel when need be(ie. next or previous click). i need the function in the thread to finish because page 2 will need the data. i need the please wait part to disappear accordingly. :)
Oct 30 '07 #5
Plater
7,872 Expert 4TB
The way I've gotten around this is:

Create a Label (or something) make it pretty big and have it say "Loading..." (or something). Then set it's .Visible property to false.
When you are going to do your intensive action, set the .Visible property to true. (Make sure you call .Refresh() on the control to make sure it gets shown)
Then set your program off doing that action. When the action completes, simply set that label with the "Loading..." text back to invisible (.Visible=false)
Oct 30 '07 #6
piercy
77
The way I've gotten around this is:

Create a Label (or something) make it pretty big and have it say "Loading..." (or something). Then set it's .Visible property to false.
When you are going to do your intensive action, set the .Visible property to true. (Make sure you call .Refresh() on the control to make sure it gets shown)
Then set your program off doing that action. When the action completes, simply set that label with the "Loading..." text back to invisible (.Visible=false)

yes, i thought of this but apprently its not proper coding. The idea being(i think) as im a trainee programmer, they want me to leanr it properly from the start so im having to learn oo c#. anyway, got a small problem now im trying it a different way. used a showdialog() to open the box and the thread does in the background then at the end of the thread i put a box.Dispose() to close it and i get the error Cannot access a disposed object. im having alook arodun for answers but if you got nay let me know.

Thanks,
piercy
Oct 30 '07 #7
Plater
7,872 Expert 4TB
Use .Close() and not .Dispose() to close the window.
Then you can get your information from it.
THEN you can call .Dispose()


I'm not sure what wasn't proper coding about all that. It's better then what I see most programs do (which is give you NO feedback)
Oct 30 '07 #8
piercy
77
Use .Close() and not .Dispose() to close the window.
Then you can get your information from it.
THEN you can call .Dispose()


I'm not sure what wasn't proper coding about all that. It's better then what I see most programs do (which is give you NO feedback)
yeah, i tried the close thing but it didnt work. so i've just hid it. does the job. as for proper code.. been huge pain in my... had to rewrite my whole app because of it. almost there though. few delaget things to do with the box now for cancel clicks etc.. *cries* i hate delegates.. dont understadn them at all. i gto sample code to do them but dont understand it. makes it really hard to learn..

Thanks again,
piercy
Oct 30 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Marina | last post by:
Hi, we have an app, that executes jobs submitted from an outside application. It executes them asynchronusly, by creating a delegate to the method that can run the job, and calling BeginInvoke on...
2
by: Jagadish | last post by:
Hi, My application requires to create a few threads on the occurance of an event E1 and the same threads need to be aborted on the occurance of another event E2. Iam not using .Net thread pool...
2
by: christopher green | last post by:
Can someone provide me with a simple example as to how to start and stop a thread that calls an instance method? All examples on the web seem to call static methods. Many thanks in advance.
4
by: LP | last post by:
Hello! I am still transitioning from VB.NET to C#. I undertand the basic concepts of Delegates, more so of Events and somewhat understand AsyncCallback methods. But I need some clarification on...
13
by: orekin | last post by:
Hi There I have been programming C# for a couple of months and am trying to master Threading. I understand that ThreadPool uses background threads (see code example in MSDN page titled...
14
by: Lior Amar | last post by:
Quick question about threads and delegates. I have the following scenario Thread A (CLASSA) spawns Thread B (CLASSB) and passes it a DelegateA to a callback Thread B Invokes a DelegateB...
2
by: Viet | last post by:
I have a couple of questions that hopefully someone could clarify for me. I have an app that uses the threading.timer to constantly poll a scanner to scan in documents. I understand that Async...
15
by: Bryce K. Nielsen | last post by:
I have an object that starts a thread to do a "process". One of the steps inside this thread launches 12 other threads via a Delegate.BeginInvoke to process. After these 12 threads are launched,...
14
by: Gotch | last post by:
Hi all, I've recently digged into C# and the whole .Net stuff. Particularly I found the idea of adding Events and Delegates to the C# language very interesting and I'm trying to use them in...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.