.dark4
.dark4
CC#
Created by .dark4 on 2/19/2023 in #help
✅ Schedule event at future DateTime based on DateOnly input, doesn't work if called <2min before
public static void ScheduleMethod(DateOnly inputDate)
{
DateTime triggerTime = new DateTime(inputDate.Year, inputDate.Month, inputDate.Day, 7, 0, 0).AddMonths(-6); // 7am 6months before input date

// Calculate the time interval between now and the trigger time
Console.WriteLine("DateTime Now: " + DateTime.Now);
Console.WriteLine("Trigger Time: " + triggerTime);
Console.WriteLine("Time until trigger: " + (triggerTime - DateTime.Now));

var delay = (int)(triggerTime - DateTime.Now).TotalMilliseconds;
if (delay > 0)
{
timer = new Timer(state => Console.WriteLine("event!!")), null, delay, Timeout.Infinite);
}
}
public static void ScheduleMethod(DateOnly inputDate)
{
DateTime triggerTime = new DateTime(inputDate.Year, inputDate.Month, inputDate.Day, 7, 0, 0).AddMonths(-6); // 7am 6months before input date

// Calculate the time interval between now and the trigger time
Console.WriteLine("DateTime Now: " + DateTime.Now);
Console.WriteLine("Trigger Time: " + triggerTime);
Console.WriteLine("Time until trigger: " + (triggerTime - DateTime.Now));

var delay = (int)(triggerTime - DateTime.Now).TotalMilliseconds;
if (delay > 0)
{
timer = new Timer(state => Console.WriteLine("event!!")), null, delay, Timeout.Infinite);
}
}
It seems to work fine during testing, but when I call ScheduleMethod(DateOnly); too close to the trigger time I get an error. System.ArgumentOutOfRangeExemption The added or subtracted value results in an un-representable DateTime. I tested this morning at approx 6:53am and it calculated the Time unit trigger, closed and tried again at approx 6:58am and got the error.
3 replies
CC#
Created by .dark4 on 12/17/2022 in #help
❔ Memory leak leading to overflow crash if server doesn't gracefully close socket with my client app
if my client app has a socket open with server, and server stops working/closes my client app gets a runaway memory leak that causes overflow. Typically when the server closes the socket what happens to the client? Should I poll the socket connection to make sure it's open and if closed, stop the socket thread (background = true)? Trying to figure out how to go abut fixing the memory leak. this is how I open the socket in my winform client
Thread tcpSocketThread = new Thread(api.ConnectToGSP);
tcpSocketThread.IsBackground = true;
tcpSocketThread.Start();
Thread tcpSocketThread = new Thread(api.ConnectToGSP);
tcpSocketThread.IsBackground = true;
tcpSocketThread.Start();
12 replies
CC#
Created by .dark4 on 12/16/2022 in #help
✅ How to pick from a field in a list in with priority
foreach (Device obj in devicesBlock)
{
Program.Log($"Found device {obj.Model} {obj.Serial} {GetConnectionType(obj.ConnectionType)}");
}
foreach (Device obj in devicesBlock)
{
Program.Log($"Found device {obj.Model} {obj.Serial} {GetConnectionType(obj.ConnectionType)}");
}
i'm iterating through a list of devices, the issue is my device can connect via usb and wifi, so my device comes out twice in the list. How can I make it pick usb and if usb isn't there pick wifi, etc
16 replies
CC#
Created by .dark4 on 12/12/2022 in #help
✅ How do I change background color of a label from a different namespace part of my app?
In my main program class I run Application.Run(new Form1()); how do I access this instance of my winform to change a label background?
69 replies