Skip to content

Instantly share code, notes, and snippets.

@iyevhen
iyevhen / pull-win-events-for-last-hour.ps1
Created April 9, 2021 11:14
Query All Event Logs for recent events for last hour using PowerShell
$old = (Get-Date).AddHours(-1)
$before_lines = 50
$after_lines = 50
Write-Host "Pulling Warn/Error Windows Events started >= $old"
Get-WinEvent -ListLog * -EA silentlycontinue |
Where-Object { $_.recordcount -AND $_.lastwritetime -gt $old } |
ForEach-Object { get-winevent -FilterHashtable @{LogName=$_.logname; StartTime=$old } -EA silentlycontinue } |
Sort-Object TimeCreated |
@iyevhen
iyevhen / AsyncManualResetEvent.cs
Created October 5, 2018 06:08
Async with ManualResetEventSlim
// https://blogs.msdn.microsoft.com/calvin_hsia/2018/09/29/using-async-with-manualreseteventslim/
// https://blogs.msdn.microsoft.com/pfxteam/2012/02/11/building-async-coordination-primitives-part-1-asyncmanualresetevent/
internal class AsyncManualResetEvent
{
private volatile TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
public Task WaitAsync() => this.tcs.Task;
public void Set()
{
@iyevhen
iyevhen / WinFormsProgress.cs
Last active August 29, 2015 14:26
Progress which doesn't throw exceptions for invalid input parameters
public void Progress(long current, long total)
{
if (InvokeRequired)
{
BeginInvoke(new Action<long, long>(Progress), current, total);
}
else
{
if (total <= 0 || current <= 0)
{