-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainForm.cs
More file actions
238 lines (191 loc) · 7.23 KB
/
Copy pathMainForm.cs
File metadata and controls
238 lines (191 loc) · 7.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
using WFDebugging.Additional;
using WFDebugging.Development.Availability;
using WFDebugging.Development.Console;
using WFDebugging.Development.Exceptions;
using WFDebugging.Development.Memory;
using WFDebugging.Development.Trace;
namespace WFDebugging
{
public partial class MainForm : Form, IConsoleReceiver
{
#region Fields
private static string _InstanceName = null;
private HardWork _HardWork = null;
#endregion
#region Constructor
public MainForm()
{
InitializeComponent();
Icon = MainResource.recycling;
ConsoleWritter.Initialize(this);
DelaysCounter.Reset(50);
MemoryWatcher.Reset();
}
static MainForm()
{
var c = new PerformanceCounterCategory(".NET CLR Exceptions");
var inst = c.GetInstanceNames();
Assembly asm = Assembly.GetExecutingAssembly();
int indexcoma = asm.ToString().IndexOf(',');
string asmName = asm.ToString().Substring(0, indexcoma);
string s = inst.FirstOrDefault(a => a == asmName);
if (string.IsNullOrEmpty(s) == true)
s = "w3wp";
_InstanceName = s;
}
#endregion
#region Constants
private const int CONSOLE_SIZE = 128;
#endregion
#region IConsoleRecevier
public void Put(string value)
{
edConsole.Text += value;
if (edConsole.Lines.Length >= CONSOLE_SIZE)
{
int firstIndex = edConsole.Lines[0].Length;
int secondIndex = edConsole.Text.IndexOf(edConsole.Lines[1], firstIndex);
if (firstIndex == secondIndex && secondIndex < edConsole.Text.Length) secondIndex++;
edConsole.Text = edConsole.Text.Substring(secondIndex);
}
edConsole.SelectionStart = edConsole.Text.Length;
edConsole.ScrollToCaret();
}
#endregion
#region Private
private void function0(string FirstName, string LastName)
{
Console.WriteLine("function 0");
function1(FirstName, LastName);
}
private void function1(string FirstName, string LastName)
{
Console.WriteLine("function 1");
function2(FirstName, LastName);
}
private void function2(string FirstName, string LastName)
{
Console.WriteLine("function 2");
IEnumerable<MethodBase> methods = TraceBuilder.Build();
bool wasFirst = false;
Console.WriteLine();
Console.WriteLine("Trace stack:");
foreach (var method in methods)
{
if (!wasFirst)
{
wasFirst = method.Name == LastName;
}
if (wasFirst)
{
ParameterInfo[] parameters = method.GetParameters();
Console.WriteLine("Function: " + method.Name);
Console.Write("Parameters: ");
for (int i = 0; i < parameters.Length; i++)
{
if (i > 0) Console.Write(", ");
Console.Write(string.Format("\t{0}: {1}", parameters[i].Name, parameters[i].ParameterType.ToString()));
}
Console.WriteLine();
}
if (method.Name == FirstName)
break;
}
}
#endregion
#region Events
private void outOfRangeExceptionToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
int[] tempArray = new int[4];
for (int i = 0; i < 10; i++)
tempArray[i] = i;
#region Never execute. Just "Release" not to optimize code
Console.WriteLine("Number of elements: " + tempArray.Length);
#endregion
}
catch (Exception ex)
{
Console.WriteLine();
Console.WriteLine(ex.ToString());
}
}
private void zeroDivisionExceptionToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
int a = 5;
int b = 0;
int c = a / b;
#region Never execute. Just "Release" not to optimize code
Console.WriteLine(string.Format("{0} {1} {2}", a, b, c));
#endregion
}
catch (Exception ex)
{
Console.WriteLine();
Console.WriteLine(ex.ToString());
}
}
private void btnCount_Click(object sender, EventArgs e)
{
Console.WriteLine();
Console.WriteLine($"Exceptions count: {ExceptionCounter.Calculate(_InstanceName)}");
}
private void twoFunctionsDepthToolStripMenuItem_Click(object sender, EventArgs e)
{
Console.WriteLine();
function1("function1", "function2");
}
private void threeFunctionsDepthToolStripMenuItem_Click(object sender, EventArgs e)
{
Console.WriteLine();
function0("function0", "function2");
}
private void btnDelay_Click(object sender, EventArgs e)
{
Console.WriteLine();
Console.WriteLine($"Max delay: {DelaysCounter.MaxDelay:N0}ms");
Console.WriteLine($"Total delay: {DelaysCounter.TotalDelays:N0}ms");
Console.WriteLine($"Delays 500ms: {DelaysCounter.Delays500ms:N0}");
Console.WriteLine($"Delays 100ms: {DelaysCounter.Delays100ms:N0}");
Console.WriteLine($"Delays 50ms: {DelaysCounter.Delays50ms:N0}");
}
private void btnGCCount_Click(object sender, EventArgs e)
{
Console.WriteLine();
Console.WriteLine($"Number of GC Handling: {MemoryWatcher.CurrentGCCount}");
Console.WriteLine($"Worst GC Handling: {MemoryWatcher.WorstGCCount}");
Console.WriteLine($"Memory usage: {GC.GetTotalMemory(false)}");
for (int i = 0, l = GC.MaxGeneration; i <= l; i++)
Console.WriteLine($"Generation {i}: {GC.CollectionCount(i)}");
}
private void btnRunWork_Click(object sender, EventArgs e)
{
if (_HardWork == null)
{
_HardWork = new HardWork();
}
else
{
_HardWork.Stop();
_HardWork = null;
}
btnRunWork.Checked = _HardWork != null;
}
private void btnWorkInfo_Click(object sender, EventArgs e)
{
if (_HardWork != null)
_HardWork.Print();
}
#endregion
}
}