|
Bernhard Hiller wrote: and makes sure that exceptions do not crash the application
Depending on your definition of terms that is impossible in C#.
There are at least three exceptions which will cause a .Net AppDomain to exit and there is absolutely nothing you can do to stop it. One of those is the stack overflow exception. You can in fact 'catch' it but it will just keep going once the catch block exits. And it terminates the AppDomain not the process.
"Starting with the .NET Framework 2.0, you can't catch a StackOverflowException object with a try/catch block, and the corresponding process is terminated by default."
StackOverflowException Class (System) | Microsoft Docs[^]
Now of course the workarounds for that depends on your definition.
1. Your main AppDomain (every process) could spin up a new AppDomain to do the actual launch. Then the 'application' can't exit only the new AppDomin will. Well at least not from this task.
2. Make sure the possible exceptions do not occur.
Bernhard Hiller wrote: And then the service crashes wi
For starters looks like you are missing try/catches and logging.
But other than that there can however be any number of reasons for that. For example consider the following scenario.
1. You have class A in DLL X.
2. You use A in your main service class in a method M()
3. You call M().
4. Nothing else in X is used until M() is called.
In the above X is not loaded until M() is called but it is loaded when M() is invoked.
Now if X is not available you are going to get an exception.
Something similar happens if you have a class C where attributes/implements uses C or where the methods have a return type or parameter that refers to C.
So the best 'safe' way to create a service is as follows.
Create a class, call it Everything, which does ALL of the functionality of the application. That means that the service class, the one with OnStart() does NOT do any application functionality.
The service class looks like the following pseudo code
class MyService
{
// It MUST be 'Object' and not 'Everything'
// There should be NO other attributes and NO
// other methods except ones that call directly
// to Everything.
Object instance
Logger logger = ...
OnStart()
{
try
{
instance = new Everything();
((Everything)instance).Start();
}
catch(Exception e)
{
logger.Error("Failed to start", e);
}
}
OnStop()
{
try
{
((Everything)instance).Stop();
}
catch(Exception e)
{
logger.Error("Failed to stop", e);
}
}
}
Of course even that is limited because 'Logger' is also a dependency that can fail to load.
|
|
|
|
|
Of course, there are some exceptions which cannot be caught. In the current scenario, about 9 out of 10 instances of that Exception are caught, which offers proof that it is not an uncatchable exception.
jschell wrote: For starters looks like you are missing try/catches and logging You missed the point. The try/catch is exactly one of the things the utility function should supply (and so it does).
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
You should read my example again. There are catchable exceptions that your current code will not catch because they can occur before the try catch that you coded is entered.
|
|
|
|
|
update: this bug occurs in VS 2019. and in the latest VS 2019 preview release ... however, after closing these IDE's when the error occurs, I don't see the collateral damage caused by VS 2017.
The song I am not hearing as I write this: [^]
like: "System.ComponentModel.Win32Exception was unhandled. Message="The parameter is incorrect" when you close a WinForm app after the run-time user changes the Opacity in a secondary Form (note: a Form with the 'Owner not set, instantiated and 'shown in main form code).
That's been around for many years, and typical strategies, like removing the EventHandlers that modify Opacity prior to closing the "Main Form," and/or disposing of secondary Forms ... don't work.
Okay: so what ? The unpleasant surprise is that not only does the latest Visual Studio Enterprise 2017 ... using VisualStudio.15.Release/15.9.13+28307.718 with Microsoft .NET Framework Version 4.8.03761 ... get trashed, but Win 10 1903 (latest regular flavor) gets the entire Desktop screwed up.
All the symptoms of some virus from hell. And, yes, I immediately did a full virus scan ... during this Win Defender scan, its major process, MsMpEng, took 75~90+% of CPU time ... that's running with "Normal" priority !
Is this "progress" ?
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
modified 13-Jun-19 0:59am.
|
|
|
|
|
This wouldn't be the first time I've seen an app do some crazy sh*t to Windows 10.
Last summer, a certain application (can't say the name), completely fubar'd the Start button in Explorer. Click Start button and launch the app or launch it from the Desktop shortcut and so something very specific in the app, but commonly done, and the Start button in Explorer would no longer work. Click it and nothing would happen, no opening of the menu at all.
The fun part was once it was broken, there was no getting it back. The problem persisted through shutdowns and restarts. And the is an app used on thousands of machines! Thankfully, due to how this app gets tested and deployed into production, it only hit about 50 machines when it broke.
Narrowed it down to how a certain set of controls (10+ years old) was being registered on the machine AND in combination with a certain Windows 10 O/S patch. The problem disappeared a couple of months later, after another set of patches and we changed how the vendor registered the controls in their installation.
I just spent 3 months on another production problem with the same app. A certain patch broke functionality in the app where a datagrid didn't work as expected any more. I was still working on it when another set of patches came down and the grid magically started working again. W T F ?!
Spent the last 3 weeks going through testing of three months worth of patches to find the one that broke the grid and the one that fixed it. Turns out they were both Office 2013 patches that updated MS Common Controls. W T F v2 ?! CommonControls is used by millions of applications, not just Office, and MS decided to disguise updating what amounts to O/S patches as Office patches?! W T F v3?!
|
|
|
|
|
You're surprised that a MS patch broke your code - W T F v4!
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
No, I'm not.
It's not our code either. It's vendors code. If it was my code, I wouldn't be relying on old controls and Crystal Reports.
What I was surprised about what the disguising of what amounts to O/S patches as Office patches.
modified 13-Jun-19 16:31pm.
|
|
|
|
|
empathy is
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
How to find the processID of an IE Tab, from ShDocVw.InternetExplorer(ShDocVw.ShellDocs). The property HWND is same for all the tabs. Need a solution to find the processId of individual tabs.
|
|
|
|
|
What makes you think that each tab in IE has a separate processID?
Do Windows Forms apps open a new thread for each form? No - so why would you expect IE to do that for each tab?
As far as I am aware (from watching processes via Task Manager) IE doesn't open a new process for each tab - it does for some but not all, which implies that the ones where it appears to are not tab related but in some way content related.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi, by contrast Chrome opens a Process for every tab, and more: [^]. Right now, I have 34 Chrome Processes running, and the Google crash-handlers for 32 and 64 bits.
Not that you needed to know that
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
I'm using the latest version of IE11
It appears as if each tab has its own process, so you could find the appropriate tab by searching for the IE instance that has the desired caption. When you find that instance, you can inspect the child hwnd's to findthe one with the caption, and send the appropriate WM_XXXX message to it.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Yes ... you need to look in "Task Manager" ... with "More Details" checked; to see how many processes ALL the browsers spawn. For only "presenting" they sure do "consume" a lot. The whole thing is now adware.
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
Gerry Schmitz wrote: For only "presenting" they sure do "consume" a lot. The whole thing is now adware. Ever since the introduction of JS, they do not just "present" content.
It is a gateway for (potential) malicious code, and should be treated as such.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I want to draw vertical bold red lines between some columns in a datagridview. I created a form and a datagridview with six columns. I want to draw red bold vertical lines between first and second columns, and forth and fifth columns. Here's my code:
private void Form1_Load(object sender, EventArgs e)
{
this.dataGridView1.Columns.Add("Col_A", "Column A");
this.dataGridView1.Columns.Add("Col_B", "Column B");
this.dataGridView1.Columns.Add("Col_C", "Column C");
this.dataGridView1.Columns.Add("Col_D", "Column D");
this.dataGridView1.Columns.Add("Col_E", "Column E");
this.dataGridView1.Columns.Add("Col_F", "Column F");
for (int i = 0; i < 50; i++)
{
this.dataGridView1.Rows.Add("A" + i.ToString(), "B" + i.ToString(), "C" + i.ToString(),
"D" + i.ToString(), "E" + i.ToString(), "F" + i.ToString());
}
for (int j = 0; j < this.dataGridView1.ColumnCount; j++)
{
this.dataGridView1.Columns[j].Width = 90;
}
this.dataGridView1.CellPainting += new DataGridViewCellPaintingEventHandler(dataGridView1_CellPainting);
}
void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
using (var redPen = new Pen(Color.Red, 3))
{
int left_x = this.dataGridView1.GetCellDisplayRectangle(dataGridView1.Columns["Col_B"].Index, this.dataGridView1.Rows[0].Index, true).X;
int right_x = this.dataGridView1.GetCellDisplayRectangle(dataGridView1.Columns["Col_D"].Index, this.dataGridView1.Rows[0].Index, true).X
+ this.dataGridView1.GetCellDisplayRectangle(dataGridView1.Columns["Col_D"].Index,this.dataGridView1.Rows[0].Index, true).Width;
int top_y = this.dataGridView1.GetCellDisplayRectangle(dataGridView1.Columns[0].Index, this.dataGridView1.Rows[0].Index, true).Y;
int bottom_y = this.dataGridView1.GetCellDisplayRectangle(dataGridView1.Columns[0].Index, this.dataGridView1.Rows[dataGridView1.Rows.Count - 1].Index, true).Y
+ this.dataGridView1.GetCellDisplayRectangle(dataGridView1.Columns[0].Index, this.dataGridView1.Rows[dataGridView1.Rows.Count - 1].Index, true).Height;
e.Graphics.DrawLine(redPen, new Point(left_x, top_y), new Point(left_x, bottom_y));
e.Graphics.DrawLine(redPen, new Point(right_x, top_y), new Point(right_x, bottom_y));
}
}
What I got is two vertical red lines in the header row, instead of the entire grid. If I reduce the number of rows to just a few so that all the rows will appear in the form what it first appears, then the red lines appear just as I wanted. But when some rows are hidden, it's screwed up. What am I missing?
Thanks.
|
|
|
|
|
Don't use CellPainting - use RowPostPaint:
private void DataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
DataGridView dgv = sender as DataGridView;
if (dgv != null)
{
Rectangle rect = dgv.GetRowDisplayRectangle(e.RowIndex, false);
int leftRow = dgv.Columns["Col_B"].Index;
int rightRow = dgv.Columns["Col_D"].Index;
int leftX = dgv.GetCellDisplayRectangle(leftRow, e.RowIndex, true).X;
int rightX = dgv.GetCellDisplayRectangle(rightRow, e.RowIndex, true).X
+ dgv.GetCellDisplayRectangle(rightRow, e.RowIndex, true).Width;
e.Graphics.DrawLine(Pens.Red, new Point(leftX, rect.Top), new Point(leftX, rect.Bottom));
e.Graphics.DrawLine(Pens.Red, new Point(rightX, rect.Top), new Point(rightX, rect.Bottom));
}
}
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thank you. It works like a charm.
|
|
|
|
|
You're welcome!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
I want to create a program that will get data from an excel sheet shows in 4 combo box with a drop drown list. For example, if I choose menu1, drop list will the corresponding submenu (i.e, submenu11 & submenu12) rather than showing all other submenus. Again, once selecting submenu11, drop down list will show only the child111 & child112.
I have already imported the data from excel but unable to sort data in a combo box.
https://i.stack.imgur.com/6ixOP.png[^]
https://i.stack.imgur.com/LzZdn.png[^]
|
|
|
|
|
You need to be able to "relate" the combo boxes (data).
Parent3->parent2->parent1->child
parent2 is filtered (LINQ where) on parent3 "selected" item.
parent1 is filtered on parent2 selected item.
etc.
They can all use the same collection: p3 "full" view; p2 view limited to p3 selected item; etc.
(If no specific selected item, default to first in each "view").
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
Thanks for your reply. But i have not so much knowledge in c#. If you give some coding help then it's very helpful for me
|
|
|
|
|
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.
So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thank you, of course, I will do my part. I just ask you if you have any coding idea then please help me. I don't tell you to do my full project.
actually, I don't have any good c# programming knowledge I'm trying to learn from the internet. And this is not my school or work project.
I already read excel using OleDb and tried LINQ to shorting data but I still not able to.
|
|
|
|
|
And there you are making a huge mistake.
Stop trying to "learn from the internet" and get a good book (or better go on a course) - Addison Wesley do some good ones, as do Wrox and Microsoft. Even download this: Dot Net Zero[^] which will give you a lot of it.
The problem is that learning from the internet is pretty much random - and if any of that is YouTube then most of it is produced by people who know little (if any) more than you do, and have no idea who to make a video or teach. So you miss a lot of stuff that you don't know that you need to know - like SQL Injection in the Bill thread code. You are trying to run before you can walk - and that's a porr way to get started.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|