|
That's normal behavior. The exception doesn't get thrown across the thread boundary.
Of course, a background worker can return any object as a result, so when I use them (And I do, extensively), I do it like this:
private void SomethingBackground(object sender, DoWorkEventArgs e)
{
try
{
}
catch (SomethingSomethingException ex)
{
}
catch (Exception ex)
{
e.Result = ex;
}
}
if (e.Result is Exception)
throw (Exception)e.Result;
else
{
}
If you're doing this a lot, you could even make a generic wrapper to centralize the code... Plenty of options.
Nevermind... Not enough caffeine...
|
|
|
|
|
Will you argue with MSDN?
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.dowork.aspx[^]
If the operation raises an exception that your code does not handle, the BackgroundWorker catches the exception and passes it into the RunWorkerCompleted event handler, where it is exposed as the Error property of System.ComponentModel.RunWorkerCompletedEventArgs. If you are running under the Visual Studio debugger, the debugger will break at the point in the DoWork event handler where the unhandled exception was raised. If you have more than one BackgroundWorker, you should not reference any of them directly, as this would couple your DoWork event handler to a specific instance of BackgroundWorker. Instead, you should access your BackgroundWorker by casting the sender parameter in your DoWork event handler
Чесноков
|
|
|
|
|
Hi Ian,
you've lost me here, in two ways:
1.
I don't understand what "in the caller" would mean, and how you would get that synchronized with the BGW having finisked. You might want to add a bit of code and/or explanation to make that clear.
2.
I also don't see a need to do anything special; in the RunWorkerCompleted event, the e.Error property automatically holds the Exception that caused the DoWork handler to finish prematurely.
Cheers.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
Yeah, this is what I get for trying to answer questions in the morning when I'm having a bad week... Heh... You're right on both counts. I abstracted all of this away months ago to run background workers with an animated progress dialog, so I can do things like:
x = Util.ProgressDialog.Show(owner, MyWorkerMethod, "Doing something") as MyResultObject;
private void MyWorkerMethod(BackgroundWorker wkr, DoWorkEventArgs e)
{
e.Result = ...
}
|
|
|
|
|
As you did not present any code, I assume that you are having a problem with Control.Invoke Method (Delegate) method.
The exception is not thrown if you try to change some control's properties directly from inside a thread. For example:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
ChangeMyText("Privet");
}
private void ChangeMyText(string myText)
{
label1.Text = myText;
}
The result will be a dead backgroundWorker. It will not say anything but die when it reaches
label1.Text = myText;
and will not throw an exception.
Instead, you have to use
label1.Invoke((Action)delegate
{
label1.Text = myText;
});
____________
Ulugbek
|
|
|
|
|
I have a C# application that is running on many network computers, across multiple subnets. These applications send and retrieve data from an sql server 2008 database. Some computers will be used to update production data for a particular production line. Others will be monitoring any changes.
When a data entry computer sends an update to the database, what I would like to do is notify all computers that are monitoring that specific production line to requery the database to get any changes. I'm really not sure how to go about this. I know Notification Services was removed from sql server. I don't know whether to use direct communication between the updating and monitoring clients (I foresee that being very messy as many computers will be sending updates at nearly the same time) or running some kind of notifying service that the clients subscribe to.
Any help would be greatly appreciated.
|
|
|
|
|
You might want to look at this[^] and see what you can do.
|
|
|
|
|
I wouldn't even consider one client notifying another, and I probably also wouldn't have a server notify multiple clients; in my view all information should be in the server, and all initiative should come from clients. So I'd rather have a data scheme that makes it pretty easy to discover when the last relevant change has been made (a last modified field in simple cases; an action in some/all stored procedures for more complex situations, resulting in a simple table entry somewhere), and have all clients poll that. IMO avoiding the need to know who the interested clients are is well worth the cost of periodic polling.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
Yeah polling is definately an option we are considering. It's the easiest by far. The problem is, the users are going to want an update every minute. That's a lot of database queries every hour. I was hoping to reduce network chatter while keeping the clients up to date.
|
|
|
|
|
NameNotYetTaken wrote: That's a lot of database queries
depends on your definitions of "many network computers" and "a lot".
One transaction per minute should be negligible. IMO a lot more would be going on when users start hitting the keyboard to enter data, or to request new reports/views.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
I'm going to stick with polling every few minutes, giving the user the option to manually refresh. It's just so much less work. Thanks for your input.
|
|
|
|
|
Definitely don't try to have each updater inform all the listeners. That way lies madness.
Whether to implement a simple listening/broadcast service or to have clients poll for updates depends on your detailed requirements, like whether you want updates to appear immediately, how many clients there will be, whether you can open enough sockets to have them all listening, etc. If it's important that updates are sent to clients immediately, you should have some sort of publish-subscribe service that they can use. If it isn't, polling the database for changes (have a LastUpdated field somewhere that is trivial to access so the polls are not resource intensive) every 30s or so should do the job, and is less intensive on the server side (since it doesn't need to hold open persistent sockets).
|
|
|
|
|
Hi,
I've done a little bit of research on the subject but couldn't find a clear answer.
Here's the situation: I have two C# projects using WPF and I would like the first project to open a window of the second project. Should I merge the two projects into a single one, or keep them separated?
Thank you in advance.
|
|
|
|
|
It should be fine to keep them separated. What I would do, if I were you, is change the second one into a class library (it's as simple as changing a setting in the project file).
|
|
|
|
|
If the interaction is trivial, you can keep them as they are and use the option Pete mentioned. If you expect the interaction to become more complex, you might opt in redesigning the projects into seperate assemblies working together.
V.
|
|
|
|
|
I need to fix the English Language as InputLanguage even the user selects Arabic keyboard for particular textbox.
Is it possible?
Once I set Inputlangaue as English, its changing to all textboxes and labels. But Iam looking to fix English language to particular textbox only.
Thanks for the ideas.
Thanks & Regards,
PARAMU
|
|
|
|
|
sir i want code for client and server architecture in c#
|
|
|
|
|
hello everyone,
i m stuck at this problem. how to track or sens lan card data
using c#. i have to keep eye on a computer communication with other and have to show log
of data that is communicated over a netwok. after lot of searching as i m able to understand it is possible through socket programming. if i m wrong then let me know........
someone help to find out this problem and also suggest me
its a big project or a small module....
i m really thankfull to you...............
|
|
|
|
|
If you're talking about capturing only your applications data, then it's quite easy to do.
If you're talking about logging any data that's going in or out of the nic, that's much more difficult, and you can't do it with the socket classes. You'll need WinPcap[^] for that.
BTW, logging all of the data is going to take a TON of resources and could easily slow down the entire machine as well as consume large amounts of memory and disk space.
Keeping track of converstations that you could report on is going to be a bit tedious. You'd have to keep track of which IP's and ports are connected to which other IP's and ports and sort your data based on those.
You'll also have to create your own packet analyzer because looking at raw packet data just isn't useful to human managers.
What you're making is a standard network sniffer and packet analyzer and this is a HUGE project.
BTW, since an estimated one third of the traffic going acrossed the nic is encrypted now-a-days, you won't be able to see what's in those packets. It's just be a ton of garbage data that won't make any sense at all.
|
|
|
|
|
yes as my project requirement i have to create log of data that is shared with other computers and
upload or download from internet......
so acc. to you socket class is not helpfull, ok then. Can we track shared files details?
well thank you very much for your reply. it helped me lot......
|
|
|
|
|
I already told you what you use to capture network traffic.
My instincts are screaming at me not to ask this question, but WHY are you trying to see all the network traffic and what does this have to do with tracking shared files?
|
|
|
|
|
Actually i m doning a project related with network monitoring
can we track name of files that is passed through
lan card of personal computer as admin. i already done to find shared folders
detail using WMI class. but its not sufficient it require to refresh code again
n again. so plz tell me its a big project or a simple module.
thank you again.......
|
|
|
|
|
Even with this description, it's the exact same project.
The only way to get a filename out of it is if you understand the SMB protocol and anaylze each packet, looking for the appropriate fields.
You can find the specifications for SMB and SMB2 here[^] and here[^].
It would also help if you had a real network sniffer and looked at what's really going over the wire when you perform the operations you are looking for.
Having said all that, that only covers copying a file from one machine to another using normal Windows file copy methods. It doesn't cover HTTP or FTP or any other non-SMB based application protocol.
|
|
|
|
|
now i m able to understand depth of this project.
its really big one. its level is high an d i m beginner.
so i change my idea, ok packet sniffer is good one.
firstly i m trying to find download complete event that system shows
after downloading.
thank you so much
|
|
|
|
|