Click here to Skip to main content
15,895,011 members
Home / Discussions / C#
   

C#

 
AnswerRe: Updating a List record within a record with c# and Linq, looking for something cleaner than add and remove Pin
Richard Deeming18-Oct-19 1:44
mveRichard Deeming18-Oct-19 1:44 
AnswerRe: Updating a List record within a record with c# and Linq, looking for something cleaner than add and remove Pin
Richard Deeming18-Oct-19 2:02
mveRichard Deeming18-Oct-19 2:02 
GeneralRe: Updating a List record within a record with c# and Linq, looking for something cleaner than add and remove Pin
jkirkerx18-Oct-19 6:41
professionaljkirkerx18-Oct-19 6:41 
AnswerI don't get this with IndexOf not finding the record Pin
jkirkerx18-Oct-19 8:24
professionaljkirkerx18-Oct-19 8:24 
SuggestionNeed help wind form code Pin
AlexJo198516-Oct-19 22:11
AlexJo198516-Oct-19 22:11 
GeneralRe: Need help wind form code Pin
dan!sh 16-Oct-19 23:17
professional dan!sh 16-Oct-19 23:17 
GeneralRe: Need help wind form code Pin
Luc Pattyn17-Oct-19 15:41
sitebuilderLuc Pattyn17-Oct-19 15:41 
AnswerRe: Need help wind form code Pin
Richard Deeming18-Oct-19 1:32
mveRichard Deeming18-Oct-19 1:32 
Why not use an async method combined with Ping.SendPingAsync[^]? Smile | :)
C#
private void OnPingSuccess()
{
    ...
}

private void OnPingFailure()
{
    ...
}

private async Task MonitorServer(IPAddress address, TimeSpan frequency, CancellationToken cancellationToken)
{
    Ping ping = new Ping();
    while (!cancellationToken.IsCancellationRequested)
    {
        PingResult result = await ping.SendPingAsync(address);
        
        if (pingresult.Status == IPStatus.Success)
        {
            OnPingSuccess();
        }
        else
        {
            OnPingFailure();
        }
        
        await Task.Delay(frequency, cancellationToken);
    }
}

private CancellationTokenSource _cancellationTokenSource;

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    _cancellationTokenSource = new CancellationTokenSource();
    _ = MonitorServer(IPAddress.Parse("10.10.9.15"), TimeSpan.FromMinutes(1), _cancellationTokenSource.Token);
}

protected override void OnClosed(EventArgs e)
{
    base.OnClosed();
    _cancellationTokenSource?.Cancel();
}
The OnPingSuccess and OnPingFailure methods should be able to directly update the UI, because they'll be running on the UI thread.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Need help wind form code Pin
Luc Pattyn18-Oct-19 1:44
sitebuilderLuc Pattyn18-Oct-19 1:44 
GeneralRe: Need help wind form code Pin
Richard Deeming18-Oct-19 3:03
mveRichard Deeming18-Oct-19 3:03 
GeneralRe: Need help wind form code Pin
Luc Pattyn18-Oct-19 3:26
sitebuilderLuc Pattyn18-Oct-19 3:26 
GeneralRe: Need help wind form code Pin
#realJSOP17-Oct-19 2:01
mve#realJSOP17-Oct-19 2:01 
QuestionExistance pointers in c# Pin
Member 774487115-Oct-19 22:38
Member 774487115-Oct-19 22:38 
AnswerRe: Existance pointers in c# Pin
OriginalGriff15-Oct-19 22:40
mveOriginalGriff15-Oct-19 22:40 
AnswerRe: Existance pointers in c# Pin
F-ES Sitecore15-Oct-19 22:47
professionalF-ES Sitecore15-Oct-19 22:47 
AnswerRe: Existance pointers in c# Pin
Richard MacCutchan15-Oct-19 22:58
mveRichard MacCutchan15-Oct-19 22:58 
AnswerRe: Existance pointers in c# Pin
Richard Deeming16-Oct-19 8:02
mveRichard Deeming16-Oct-19 8:02 
AnswerRe: Existance pointers in c# Pin
Anandkumar Prajapati24-Oct-19 22:08
professionalAnandkumar Prajapati24-Oct-19 22:08 
Questionbetter way to serialize a DataView, exclusive of filtered rows ? Pin
BillWoodruff15-Oct-19 21:16
professionalBillWoodruff15-Oct-19 21:16 
AnswerRe: better way to serialize a DataView, exclusive of filtered rows ? Pin
Richard Deeming16-Oct-19 7:57
mveRichard Deeming16-Oct-19 7:57 
GeneralRe: better way to serialize a DataView, exclusive of filtered rows ? Pin
BillWoodruff16-Oct-19 14:45
professionalBillWoodruff16-Oct-19 14:45 
Questionextract pdf images Pin
Member 774487114-Oct-19 23:58
Member 774487114-Oct-19 23:58 
AnswerRe: extract pdf images Pin
Luc Pattyn15-Oct-19 0:15
sitebuilderLuc Pattyn15-Oct-19 0:15 
GeneralRe: extract pdf images Pin
Member 774487115-Oct-19 2:34
Member 774487115-Oct-19 2:34 
GeneralRe: extract pdf images Pin
Luc Pattyn15-Oct-19 2:57
sitebuilderLuc Pattyn15-Oct-19 2:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.