System.ComponentModel.Win32Exception (0x80004005): Error creating window handle.
at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.ScrollableControl.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.OnParentVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.ScrollableControl.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Form.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.Show()
<pre>19-03-2019 20:13:15 System.OutOfMemoryException: Out of memory.
at System.Drawing.Graphics.FromHdcInternal(IntPtr hdc)
at System.Drawing.Font.GetHeight()
at System.Drawing.Font.get_Height()
at System.Windows.Forms.DataGridViewRow..ctor()
at System.Windows.Forms.DataGridViewRow.Clone()
at System.Windows.Forms.DataGridViewRowCollection.get_Item(Int32 index)
at System.Windows.Forms.DataGridView.OnClearingRows()
at System.Windows.Forms.DataGridViewRowCollection.ClearInternal(Boolean recreateNewRow)
at System.Windows.Forms.DataGridView.RefreshColumnsAndRows()
at System.Windows.Forms.DataGridView.OnBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.ScrollableControl.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.OnParentVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.ScrollableControl.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Form.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.Show()
at TEXTILE_EXTNL_DISPLAY.MainForm.<Active_Timer_Tick>d__22.MoveNext()
What I have tried:
private void MainForm_Load(object sender, EventArgs e)
{
}
public MainForm()
{
InitializeComponent();
Active_Timer.Interval = 100;
Active_Timer.Tick += new EventHandler(Active_Timer_Tick);
Active_Timer.Start();
this.WindowState = FormWindowState.Maximized;
this.Location = new Point(0, 0);
this.Size = Screen.PrimaryScreen.WorkingArea.Size;
}
[DllImportAttribute("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize", ExactSpelling = true, CharSet =
CharSet.Ansi, SetLastError = true)]
private static extern int SetProcessWorkingSetSize(IntPtr process, int minimumWorkingSetSize, int
maximumWorkingSetSize);
public static void FlushMemory()
{
GC.Collect();
GC.WaitForPendingFinalizers();
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
}
}
private async void Active_Timer_Tick(object sender, EventArgs e)
{
try
{
bool IsOpen = false;
if ((DateTime.Now.Minute == 3) || (DateTime.Now.Minute == 33) || (DateTime.Now.Minute == 4) || (DateTime.Now.Minute == 34))
{
FlushMemory();
ELMEASURE frm1 = new ELMEASURE();
ELMEASURE1 frm2 = new ELMEASURE1();
#region ADD Screens
if ((DateTime.Now.Minute == 3) || (DateTime.Now.Minute == 33))
{
Active_Timer.Stop();
frm1.Location = new Point(0, 0);
frm1.Size = Screen.PrimaryScreen.WorkingArea.Size;
frm1.StartPosition = FormStartPosition.CenterScreen;
frm1.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
frm1.Dock = DockStyle.Fill;
frm1.Show();
await Task.Delay(60000);
frm1.Close();
}
if ((DateTime.Now.Minute == 4) || (DateTime.Now.Minute == 34))
{
frm2.Location = new Point(0, 0);
frm2.Size = Screen.PrimaryScreen.WorkingArea.Size;
frm2.StartPosition = FormStartPosition.CenterScreen;
frm2.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
frm2.Dock = DockStyle.Fill;
frm2.Show();
await Task.Delay(60000);
frm2.Close();
}
#endregion
MainForm mainFrm = new MainForm();
mainFrm.ShowDialog();
}
else
{
Active_Timer.Stop();
this.Hide();
SqlConnection con = new SqlConnection(connection);
con.Open();
SqlCommand cmd = new SqlCommand("Select id,Form_Name,Type,DeviceID,DepartmentName,Status from Textile.dbo.Display_External_Selected where Status='True'", con);
dt_Forms = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt_Forms);
arrDeviceID = new ArrayList();
int deviceCount = 0;
int ID;
foreach (DataRow row in dt_Forms.Rows)
{
Globals.StrShift = _AllData.CurrentShift();
Frm_Name = row["Form_Name"].ToString();
DeviceID = row["DeviceID"].ToString();
DepartmentName = row["DepartmentName"].ToString();
DeptType = row["Type"].ToString();
deviceCount = DeviceID.Split(',').Length;
Globals.StrDeviceCount = deviceCount;
Globals.StrDeviceID = DeviceID;
Globals.StrDeptName = DepartmentName;
Globals.StrDeptType = DeptType;
string[] strs = DeviceID.Split(',');
for (int i = 0; i < strs.Length; i++)
{
Globals.ArrDeviceID.Add(strs[i]);
}
ID = Convert.ToInt16(row["id"].ToString());
var str_array = Frm_Name.Split(',');
for (var i = 0; i < str_array.Length; i++)
{
Active_Timer.Stop();
conn = new SqlConnection(connection);
conn.Open();
cmdd = new SqlCommand("select Form_Active from Textile.dbo.Display_Parameters where Form_No=" + str_array[i] + "", conn);
reader = cmdd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
Active_Frm_Name = (string)reader["Form_Active"];
IsOpen = true;
string formTypeFullName = string.Format("{0}.{1}", this.GetType().Namespace, Active_Frm_Name);
Type type = Type.GetType(formTypeFullName, true);
frmShow = (Form)Activator.CreateInstance(type);
frmShow.Location = new Point(0, 0);
frmShow.Size = Screen.PrimaryScreen.WorkingArea.Size;
frmShow.StartPosition = FormStartPosition.CenterScreen;
frmShow.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
frmShow.Dock = DockStyle.Fill;
FormCollection fc = Application.OpenForms;
if (IsOpen == true)
{
foreach (Form frm in fc)
{
frm.Hide();
}
FlushMemory();
frmShow.Show();
IsOpen = false;
}
if (IsOpen == false)
{
int timeDelay = 12000;
await Task.Delay(timeDelay);
}
Active_Timer.Enabled = false;
Active_Timer.Start();
frmShow.Close();
}
reader.Close();
}
}
}
con.Close();
}
}
catch (Exception Ex)
{
Logger onLogger = new Logger();
onLogger.WriteErrorLog(Ex.ToString());
}
finally
{
frmShow.Dispose();
}
}