Skip to content

Commit 8f897f0

Browse files
committed
Now if there is a crash on UI thread CrashReporter.NET will use current UI thread to show the crash report dialog.
1 parent b2e3b78 commit 8f897f0

13 files changed

Lines changed: 434 additions & 621 deletions

CrashReporter.NET/CrashReport.Designer.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CrashReporter.NET/CrashReport.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ internal partial class CrashReport : Form
2626
public CrashReport(ReportCrash reportCrashObject)
2727
{
2828
InitializeComponent();
29-
HelperMethods.UseSystemFont(this);
3029
toolTip.ToolTipTitle = Resources.ToolTipTitle;
3130
_reportCrash = reportCrashObject;
3231
Text = string.Format(Resources.TitleText, _reportCrash.ApplicationTitle,

CrashReporter.NET/CrashReport.resx

Lines changed: 279 additions & 540 deletions
Large diffs are not rendered by default.

CrashReporter.NET/HelperMethods.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,5 @@ public static string GetWindowsVersion()
8686
}
8787
return String.Empty;
8888
}
89-
90-
internal static void UseSystemFont(Form form)
91-
{
92-
form.Font = SystemFonts.MessageBoxFont;
93-
SetFont(form.Controls);
94-
}
95-
96-
private static void SetFont(IEnumerable controls)
97-
{
98-
foreach (Control control in controls)
99-
{
100-
var font = new Font(SystemFonts.MessageBoxFont.FontFamily, control.Font.SizeInPoints, control.Font.Style,
101-
GraphicsUnit.Point);
102-
control.Font = font;
103-
if (control.HasChildren)
104-
{
105-
SetFont(control.Controls);
106-
}
107-
}
108-
}
10989
}
11090
}

CrashReporter.NET/ProgressDialog.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ internal partial class ProgressDialog : Form
77
public ProgressDialog()
88
{
99
InitializeComponent();
10-
HelperMethods.UseSystemFont(this);
1110
}
1211
}
1312
}

CrashReporter.NET/ProgressDialog.resx

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@
119119
</resheader>
120120
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
121121
<data name="pictureBoxIcon.Location" type="System.Drawing.Point, System.Drawing">
122-
<value>12, 12</value>
122+
<value>12, 10</value>
123123
</data>
124124
<data name="pictureBoxIcon.Size" type="System.Drawing.Size, System.Drawing">
125-
<value>80, 46</value>
125+
<value>80, 40</value>
126126
</data>
127127
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
128128
<data name="pictureBoxIcon.SizeMode" type="System.Windows.Forms.PictureBoxSizeMode, System.Windows.Forms">
@@ -132,40 +132,70 @@
132132
<data name="pictureBoxIcon.TabIndex" type="System.Int32, mscorlib">
133133
<value>0</value>
134134
</data>
135+
<data name="&gt;&gt;pictureBoxIcon.Name" xml:space="preserve">
136+
<value>pictureBoxIcon</value>
137+
</data>
138+
<data name="&gt;&gt;pictureBoxIcon.Type" xml:space="preserve">
139+
<value>System.Windows.Forms.PictureBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
140+
</data>
141+
<data name="&gt;&gt;pictureBoxIcon.Parent" xml:space="preserve">
142+
<value>$this</value>
143+
</data>
144+
<data name="&gt;&gt;pictureBoxIcon.ZOrder" xml:space="preserve">
145+
<value>1</value>
146+
</data>
135147
<data name="labelMessage.AutoSize" type="System.Boolean, mscorlib">
136148
<value>True</value>
137149
</data>
138150
<data name="labelMessage.Font" type="System.Drawing.Font, System.Drawing">
139-
<value>Tahoma, 12px</value>
151+
<value>Segoe UI, 9pt</value>
140152
</data>
141153
<data name="labelMessage.Location" type="System.Drawing.Point, System.Drawing">
142-
<value>98, 27</value>
154+
<value>98, 22</value>
143155
</data>
144156
<data name="labelMessage.Size" type="System.Drawing.Size, System.Drawing">
145-
<value>199, 14</value>
157+
<value>189, 15</value>
146158
</data>
147159
<data name="labelMessage.TabIndex" type="System.Int32, mscorlib">
148160
<value>1</value>
149161
</data>
150-
<data name="$this.Localizable" type="System.Boolean, mscorlib">
151-
<value>True</value>
162+
<data name="labelMessage.Text" xml:space="preserve">
163+
<value>Sending crash report. Please wait...</value>
164+
</data>
165+
<data name="&gt;&gt;labelMessage.Name" xml:space="preserve">
166+
<value>labelMessage</value>
152167
</data>
168+
<data name="&gt;&gt;labelMessage.Type" xml:space="preserve">
169+
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
170+
</data>
171+
<data name="&gt;&gt;labelMessage.Parent" xml:space="preserve">
172+
<value>$this</value>
173+
</data>
174+
<data name="&gt;&gt;labelMessage.ZOrder" xml:space="preserve">
175+
<value>0</value>
176+
</data>
177+
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
178+
<value>True</value>
179+
</metadata>
153180
<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing">
154-
<value>7, 17</value>
181+
<value>7, 15</value>
155182
</data>
156183
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
157-
<value>464, 70</value>
184+
<value>464, 62</value>
158185
</data>
159186
<data name="$this.Font" type="System.Drawing.Font, System.Drawing">
160-
<value>Segoe UI, 13px</value>
187+
<value>Segoe UI, 9pt</value>
161188
</data>
162189
<data name="$this.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
163190
<value>3, 5, 3, 5</value>
164191
</data>
165192
<data name="$this.StartPosition" type="System.Windows.Forms.FormStartPosition, System.Windows.Forms">
166193
<value>CenterParent</value>
167194
</data>
168-
<data name="labelMessage.Text" xml:space="preserve">
169-
<value>Sending crash report. Please wait...</value>
195+
<data name="&gt;&gt;$this.Name" xml:space="preserve">
196+
<value>ProgressDialog</value>
197+
</data>
198+
<data name="&gt;&gt;$this.Type" xml:space="preserve">
199+
<value>System.Windows.Forms.Form, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
170200
</data>
171201
</root>

CrashReporter.NET/ReportCrash.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.ComponentModel;
23
using System.Diagnostics;
34
using System.Drawing.Imaging;
45
using System.Globalization;
@@ -74,11 +75,6 @@ public class ReportCrash
7475
/// </summary>
7576
public bool IncludeScreenshot = true;
7677

77-
/// <summary>
78-
/// Gets or Sets the current culture to use by the library.
79-
/// </summary>
80-
public CultureInfo CurrentCulture;
81-
8278
/// <summary>
8379
/// Specify whether CrashReporter.NET should send crash reports only for new problems (duplicates detected by Doctor Dump free cloud service).
8480
/// </summary>
@@ -96,14 +92,12 @@ public class ReportCrash
9692
internal string ScreenShot;
9793

9894
/// <summary>
99-
/// Sends exception report directly to receiver email address provided in ToEmail.
95+
/// Object use to send exception report to your Inbox.
10096
/// </summary>
101-
public void Send()
97+
/// <param name="toEmail">Email where you want to receive crash reports.</param>
98+
public ReportCrash(string toEmail)
10299
{
103-
if (Exception != null)
104-
{
105-
Send(Exception);
106-
}
100+
ToEmail = toEmail;
107101
}
108102

109103
/// <summary>
@@ -143,11 +137,19 @@ public void Send(Exception exception)
143137
{
144138
Application.EnableVisualStyles();
145139
}
146-
var thread = new Thread(() => new CrashReport(this).ShowDialog()) { IsBackground = false };
147-
thread.CurrentCulture = thread.CurrentUICulture = CurrentCulture ?? Thread.CurrentThread.CurrentCulture;
148-
thread.SetApartmentState(ApartmentState.STA);
149-
thread.Start();
150-
thread.Join();
140+
CrashReport crashReport = new CrashReport(this);
141+
if (Thread.CurrentThread.GetApartmentState().Equals(ApartmentState.MTA))
142+
{
143+
var thread = new Thread(() => crashReport.ShowDialog()) {IsBackground = false};
144+
thread.CurrentCulture = thread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
145+
thread.SetApartmentState(ApartmentState.STA);
146+
thread.Start();
147+
thread.Join();
148+
}
149+
else
150+
{
151+
crashReport.ShowDialog();
152+
}
151153
}
152154
}
153155

CrashReporterTest/CrashReporterTest.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
<PropertyGroup>
3535
<SignAssembly>true</SignAssembly>
3636
</PropertyGroup>
37+
<PropertyGroup>
38+
<ApplicationManifest>app.manifest</ApplicationManifest>
39+
</PropertyGroup>
3740
<ItemGroup>
3841
<Reference Include="System" />
3942
<Reference Include="System.Drawing" />
@@ -60,6 +63,7 @@
6063
<AutoGen>True</AutoGen>
6164
<DependentUpon>Resources.resx</DependentUpon>
6265
</Compile>
66+
<None Include="app.manifest" />
6367
<None Include="Properties\Settings.settings">
6468
<Generator>SettingsSingleFileGenerator</Generator>
6569
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

CrashReporterTest/FormMain.Designer.cs

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CrashReporterTest/Program.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,14 @@ static void Main()
2626

2727
public static void SendCrashReport(Exception exception, string developerMessage = "")
2828
{
29-
var reportCrash = new ReportCrash
29+
var reportCrash = new ReportCrash("Email where you want to receive crash reports.")
3030
{
31-
CurrentCulture = new CultureInfo("en-US"),
32-
AnalyzeWithDoctorDump = true,
3331
DeveloperMessage = developerMessage,
34-
ToEmail = "Email where you want to receive crash reports.",
3532
DoctorDumpSettings = new DoctorDumpSettings
3633
{
3734
ApplicationID = new Guid("Application ID you received from DrDump.com"),
3835
OpenReportInBrowser = true
39-
},
36+
}
4037
};
4138

4239
reportCrash.Send(exception);

0 commit comments

Comments
 (0)