|
Not wishing to touch your design (which sounds pretty dodgy), just explain this exception: A ThreadAbortException is raised within a thread when Thread.Abort is called on it. Either your code, or some framework code, must be doing that. My guess would be that the web framework kills any threads that were started as the result of a request once the request is finished, but it is just a guess – hopefully someone can post who actually knows the answer.
Your posted code is swallowing exceptions – and it also appears to be using exceptions as part of normal code flow control, which is probably worse.
|
|
|
|
|
Thank for reply.
This is not based on web request process. This is schedule based background work. the user can update the time of the scheduling from web page.
on the application host the thread initiate the process.At beginning the thread started and waiting for that particular schedule time( which is getting from database)And that thread is waiting until that time using manualResetevent ( block the thread process using waitOne(milSec).
If comes at the particular times, the process is read the xml file and that data would be updated to database. for that xml reading
XmlDocument configDoc = new XmlDocument();
XmlNode parentNode = null;
configDoc.Load(tConfigfilePath);
if (null != configDoc)
{
XmlNode Id = configDoc.SelectSingleNode("/CCC/AAA");
Id.SetValue("ZZZ", detectOid.InnerText);
}
Then that value inserted to database. Again that waiting for next day time using below code. In between time if any changed happened on the xml file, suddenly the catch ( with in a while loop) is catch the exception.
private void XMlreaderProcess()
{
long delayTimeSpanTicks = 0;
try
{
while (Active)
{
try
{
triggerCtrl.Reset();
if (delayTimeSpanTicks == 0)
{
triggerCtrl.WaitOne();
}
else
{
triggerCtrl.WaitOne(new TimeSpan(delayTimeSpanTicks));
}
StartProcess();
}
catch(Exception ex)
{
delayTimeSpanTicks = 0;
}
finally
{
}
}
}
catch(Exception ex)
{
}
finally
{
Active= false;
}
|
|
|
|
|
Hi,
How to create a license file or digital signature for a setup file
on c#.
|
|
|
|
|
Hi All
I know this may not be the right place for this but can't see an appropriate place and hope someone is familiar with the issue i am having.
I have a c# app which i am deploying using studio 2008 deployment project.
Thing is i will be installing a 'loose' file and I only want to install it if the file does not exists on the target location or is newer than the one that does already exist.
A simple task i thought!! but i can't find any worthwhile help on this anywhere (probably googling wrongly).
Be very grateful if anyone can help me with this.
Thanks in advance
|
|
|
|
|
Google for Custom Action. You will need to add one to your setup to validate the file if it not being controlled via the setup package
No comment
|
|
|
|
|
Hi,
How to find coordinates and width and height of each word in a pdf file using iTextSharp. I found few articles on iTextSharp to create pdf files and convert documents to pdf files.
Can anybody help me to find out the coordinates of each word. Thanks in advance.
modified 15-Dec-11 5:51am.
|
|
|
|
|
I want to analyse the Sql Syntax,
and divide the Sql string in to different parts,
like "selected columns part","selected tables part","where part"
and build classes for these parts,
For Example:
Select CompanyName from Companys
"CompanyName" is the "Selected Column" part;
"Company" is the "Selected Table" part;
Then put these parts into Orient-object classes;
The problem I met is that:
How can I anlyse the syntax of "Sql Query",and sperated them in to different parts?
Best wishes;
|
|
|
|
|
It's not that simple (it never is).
Despite SQL syntax being basically simple, it hides a lot of potential complexity in the form of nested queries, joins, and so forth. To do a job that actually is of some use, you need to parse SQL properly.
Google can help (parsing SQL has been done before): Parse SQL query[^]
If nothing else, it gives you a number of starting points. Time for some reading!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Really thanksful for your reply,
I've done a lot on this,
and already to generate sql query by Objective Codings,
But I cant do it reversely,
you know make Objects by Sql query.
Sincerely;
|
|
|
|
|
Hi All!
I have created an Event Handler for several buttons. When a button is clicked I am searching through my array of buttons to see which one has been clicked:
//my event handler
void Button_Click(object sender, EventArgs e)
{
Button ClickedButton = (Button)sender;
if(ClickedButton == null)
return;
for(int i = 0; i < MaxButtons; ++i)
{
if(ClickedButton == MyButtons[i])
//Do Stuff!
return;
}
}
Is there a better way of finding out which button has been clicked?
Thanks for any advice!
Mike
|
|
|
|
|
Huh?
sender is the Control that caused your handler being called. So if it was a Button, then (Button)sender is it. You already have that in your code. Didn't you understand your own code? Or did you mean to ask something else?
BTW: if several Buttons share a single Click handler, and need a slightly different handing, then you could store a parameter in the Button's Tag property, or you could maintain a Dictionary<button, someparametertype=""> to look up the parameter value.
|
|
|
|
|
Thanks Luc,
Yes, I do have a single event handler for several buttons. I will take a look at the tag property and see if that will do what I want - what I have seen on the net looks like it should.
I will let you know how I get on
Cheers
Mike
|
|
|
|
|
Hi Luc,
That was easy!
All I do now is set the tag to an integer value when initiating the buttons, and then in my Event Handler retrieve the tag value and that identifies which button was pressed.
Thanks very much for your help!
Mike
|
|
|
|
|
You're welcome.
|
|
|
|
|
Here's another alternative:
private void ButtonsForWhatEver_Click(object sender, EventArgs e)
{
switch((sender as Button).Name)
{
case "btn_whatEver1":
break;
case "btn_whatEver2":
break;
case "btn_whatEver4":
break;
default:
break;
}
} Discussion:
1. there are endless discussions here on CP, and StackOverFlow, about the relative efficiency of using a string in a switch statement compared to a numeric value. For example:[^]
1.a. if your "buttons are not being pushed" a thousand times a minute , in this case using a string will probably have an insignificant performance hit.
1.b. what the compiler does in translating structs into IL is quite complex: with a switch statement with many string conditions, I read that it will generate and use a hash-table. In other circumstances, I read, a Dictionary is used "under the hood." For an in-order sequence of integers: the most performant possible jump-table is created, I read.
2. In a Button Click EventHandler you really don't need to worry that "sender" is going to be "null," or not a Button: code that would invoke a Button EventHandler directly, without a Button being pushed, would be an abomination
2.a. If you did have code in a Button Click EventHandler that needed to be used from outside the BC EH, then that code should be broken out into its own method, and then the BC EH can call that method.
best, Bill
When I consider the brief span of my life, swallowed up in the eternity before and after, the little space which I fill, and even can see, engulfed in the infinite immensity of spaces of which I am ignorant, and which knows me not, I am frightened, and am astonished at being here rather than there; for there is no reason why here rather than there, now rather than then. Blaise Pascal
modified 15-Dec-11 3:58am.
|
|
|
|
|
Hi Bill,
Thanks for replying
i did think of using a switch, but I may have up to 250 buttons, which would make the switch statement rather large!
I have just tried Luc's suggestion of using the tag property, and this seams to have done it very efficiently. I will have to look further in to tags to see what else I can do!
Cheers
Mike
|
|
|
|
|
250 buttons? What is the rationale for using one event handler for 250 buttons? What's wrong with one event handler per button? Is there alot of common code for each button? For 250 buttons I would have an event hander for each button and create a method which executes common code. The button handler would call this method and pass (to the method) parameters specific for each button.
|
|
|
|
|
250 buttons? are you out of your mind? that is horrible.
If you need a large grid full of buttons, and you care about responsiveness a tiny bit, then go for a single Control (I'd suggest a Panel), and:
- paint the grid lines and the button texts/images (if any) in its Paint handler;
- and inside its MouseDown handler, figure out which virtual button is clicked (the e.X and e.Y parameters give you the mouse-down coordinates relative to the top left corner of the Control), then act on that.
|
|
|
|
|
... since this is a kind of a long response, with a lot of content that does not relate directly to the first thread/set of comments on the OP's thread, and code examples, I will post this here as a separate "fresh" response to the OP ...Miwin Solutions wrote: but I may have up to 250 buttons Hi Mike,
Like the other commentators on this thread, I "gasp" at the idea of 250 buttons ! But, I also assume it's possible that not all of them are shown/visible at the same time. "bunches of them" on each TabPage in a TabControl is one idea that comes to mind.
Some more information from you can help further refine the proposed solutions here: and, imho, definitely influence implementation strategy:
1. how are these buttons "organized:" are they in a row, column matrix ? Are they "all over the place" ? Are they inside different containers, or in nested containers ?
2. will every one of them invoke/execute/call a unique function (perhaps in addition to some common functionality they all invoke) ? Or, will "bunches" of them execute the same code ?
2a. a rarer case (?) would be the requirement that code that each (or some number of) Button(s) executes changes during the application lifetime.
3. is the unique code each, or "bunches of," Buttons will call "elaborate," or "simple" ?
If you use a Tag, you have to cast the Tag back to whatever object type you require ... again I think this is no big deal, unless you are getting a thousand button presses a minute ... and then ? ... you're going to need some kind of "selector structure" which that converted Tag can be used to access to select the code required to be invoked. That could be a switch statement, a nested if then/else block (please no, anything but that one), or, as Luc suggested, a Dictionary look-up.
Hints:
1. case statements in a switch block can be "or'd;" to create "bunches," all with the same handler:
case "button4":
case "button5":
Console.WriteLine((sender as Button).Name);
break; But, once written that way, you are not going to be able to modify without re-coding, and re-compiling.
2. executable code (anonymous functions) can be stored directly in a Tag object and invoked with one extra level of casting: you'll need a delegate:
private delegate void uniqueButtonCodeToExecute(); And, you can set code to be executed in the Click EventHandler like this:
SomeButton.Tag = new uniqueButtonCodeToExecute(() => Console.WriteLine("in Button8's unique code")); And then, the Click EventHandler for each Button could work like this:
private void ButtonUniqueCode_Click(object sender, EventArgs e)
{
((sender as Button).Tag as uniqueButtonCodeToExecute)();
} 3. Similarly, you could have a Dictionary with KeyValue Pairs whose Keys were of Type object, and whose Values were of Type anonymous function/method, or valid code for calling an external named function/method:
private Dictionary<object, uniqueButtonCodeToExecute> ButtonCodeDictionary = new Dictionary<object,uniqueButtonCodeToExecute>(); You'd create the Dictionary entry per Button like this:
ButtonCodeDictionary.Add(SomeButton, () => Console.WriteLine("in Button8's unique code")); Then, the Button Click EventHandler could be:
private void ButtonsForWhatEver2_Click(object sender, EventArgs e)
{
ButtonCodeDictionary[sender]();
} What if you want get the definition of the code unique to each Button out of the assignment as anonymous function (which I'd recommend for code clarity, maintenance, re-usability, etc.) ? Then you can use something like this:
ButtonCodeDictionary.Add(theButton, () => SomeUniqueButtonsMethod("Button8")); In this example the lambda notation () => does the right thing to set the delegate to an externally defined method, passing a parameter: here's what the function could look like:
private void SomeUniqueButtonsMethod(string buttonName)
{
Console.WriteLine(buttonName);
} So, you have a wide range of options to use here.
My own choice, assuming 250 buttons, and every one of them executing a different method/function, would be to use the Button's Tag, store one of a sequence of integers in each Tag, and then use the Tag cast to an Int as the selector in a big switch statement: after all, you could execute code anywhere in the application, inside any of those switch cases that are selected, via techniques such as cross-class method/function exposure, invoking static members of a static "uber-class" that all classes could see, etc.
But, I remain convinced that a scenario that uses 250 buttons, each with unique code to be executed, is probably a sign that the code strategy, the architecture, really needs to be changed.
I've been playing around with storing executable code in Dictionaries for several years: for example, in this article for DevX:[^], written for .NET 2.0, in which I make the Value of the Dictionary's KeyValue Pairs, an actual delegate definition itself, and then use "DynamicInvoke" to execute them (scroll down in the article to the section titled: "Introducing Dynamic Code Dictionaries").
When I consider the brief span of my life, swallowed up in the eternity before and after, the little space which I fill, and even can see, engulfed in the infinite immensity of spaces of which I am ignorant, and which knows me not, I am frightened, and am astonished at being here rather than there; for there is no reason why here rather than there, now rather than then. Blaise Pascal
modified 15-Dec-11 20:58pm.
|
|
|
|
|
Thank you to those who made an attempt to assist me.
The problem is resolved. All I had to do was double click on Line 14 in the Error List in VS 10, and the fix code was inserted.
The application now runs correctly.
Any new developers might consider picking up Dan Clark's Beginning C# Object Oriented Programming. I could have saved myself about 5 hours of frustration, had I skipped to Chapter 5 and read it.
|
|
|
|
|
I would also suggest Charles Petzold's .NET Book Zero[^] as a great (and free) introduction to the basics of .NET and C#.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Thank you for the suggestion. I am on my way to retrieve the Petzold reading.
|
|
|
|
|
re Dan Clark's book: in terms of new developers, who are not coming from a more formal development methodology, experienced in structured-code informed by CS theory background, not already having experience with flow-diagrams, UML, etc.
I specifically would not recommend this book: the first sixty pages are general theory, and you don't get to the C# "meat," until much later in the book. But, if you are person for whom state-machine concepts, flow-chart diagrams, and UML models, are already salient: go for it
There are many better introductory books, imho, for C#, among them I vote for ones by Jesse Liberty, Matthew MacDonald, Troelsen, Sells, etc., perhaps the one from Deitel, and even Petzold's very old first book, as well as his current free one mentioned.
best, Bill
When I consider the brief span of my life, swallowed up in the eternity before and after, the little space which I fill, and even can see, engulfed in the infinite immensity of spaces of which I am ignorant, and which knows me not, I am frightened, and am astonished at being here rather than there; for there is no reason why here rather than there, now rather than then. Blaise Pascal
|
|
|
|
|
Bill:
I noted the authors you list, and will research further. As I do not have a background in CS (other than the watered down clases provided for teaching credentialing) I scoured the reviews on iProgrammer and Amazon.
There are going to be issues with most books and/or tutorials, and I find myself irritated with the "casual" editing(simple errors in grammar/syntax) in many books, but I "deal". It's almost as if there is a race to the publisher, and then a laundry list posted of errata (?). I am not speaking of language (the u in color outside of the US), but rather when the word should be window, and widow is the printed text. Again, I rant.
As to the Clark book, I enjoy his "teaching method" as he explains how something works and why, and I don't feel stupid, just ignorant. I admit to enjoying DFD so I was probably enchanted.
Thank you again for your insight and recommendations.
Deborah
|
|
|
|
|
Hi Deborah,
fyi: I've been involved with technical editing and documentation strategy for many years: most recently as a paid technical reviewer for two major .NET books from Addison-Wesley.
I omitted from my recommendations what I consider to the ultimate C# book, the palladium, the ne plus ultra, mainly because I believe it is a very advanced book: Jon Skeet's "C# in Depth"[^] (Manning Press, 2nd. edition now available).
My own review of that book is here:[^]. But you'll note some of the most voted-up reviews on Amazon for this book recommend it as a beginner's book.
I think the type of book that is "best" for someone starting any computer language, embedded in (an expression of) a complex FrameWork, and "incarnate" in a complex IDE, really is not a one-size-fits-all "answer."
What I do know is that in my own experience, as I immediately jumped on the C# bandwagon several years ago, from VB6, was that Petzold's first book helped me get "off the ground," and then Jesse Liberty's book, Programming C# (O'Reilley ... new revisions issued several times), really gave me what I needed, in conjunction with Matthew MacDonald's very clean expository prose.
For myself, it is only at this point, that I am able to read Troelsen and really follow the content about what happens "under-the-hood" in the FrameWork and the CLR, and find that salient, and relevant. And, only at this point, that I can find, in constantly re-reading the chapters in Skeet's book, continuing re-appraisal of my own understanding (and I'm still a long way from mastery of the depths of Skeet's astounding mind's thoughts and concepts).
But, that's just the story of one pilgrim: someone with a good academic CS background, someone who's already "grounded in OO," could have, I believe, very different needs, and make very different choices for a first book.
And, perhaps, also a matter of temperament ? Some folks cognitive style in technical problem-solving is very much top-down: they are most comfortable starting very high-level abstractions, and moving "down" to code-on-the-ground.
People like me are more "bottom-up" in learning style: I have to be constantly experimenting in code, trying out ideas, observing what happens, and then going back to the conceptual level, and the books for inspiration and, hopefully, understanding, followed by step-wise refinement of my own techniques.
best, Bill
When I consider the brief span of my life, swallowed up in the eternity before and after, the little space which I fill, and even can see, engulfed in the infinite immensity of spaces of which I am ignorant, and which knows me not, I am frightened, and am astonished at being here rather than there; for there is no reason why here rather than there, now rather than then. Blaise Pascal
|
|
|
|
|