Skip to content

Commit

Permalink
Merge pull request #3 from DevElkami/develop
Browse files Browse the repository at this point in the history
Fix async call
  • Loading branch information
DevElkami committed Apr 22, 2023
2 parents 59b030a + 147e056 commit 05d8459
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
30 changes: 28 additions & 2 deletions RESTest/RESTestCore.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System.Data;
using System.Net;
using System.Net.Http.Headers;
using System.Text;
Expand All @@ -10,6 +11,17 @@ namespace RESTestCore;
/// </summary>
public class RESTestCore : INotifyPropertyChanged
{
private readonly SynchronizationContext syncContext = null!;

public RESTestCore()
{
}

public RESTestCore(SynchronizationContext syncContext)
{
this.syncContext = syncContext;
}

#region Properties
public String Url { get; set; } = null!;
public String Data { get; set; } = "";
Expand Down Expand Up @@ -48,6 +60,9 @@ public enum MethodEnum

public async Task SendAsync()
{
if (syncContext == null)
throw new NoNullAllowedException("You must give a context");

await Task.Factory.StartNew(() => Send());
}

Expand Down Expand Up @@ -102,8 +117,19 @@ public void Send()
}
finally
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("HttpResponse"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("HttpContent"));
if (syncContext != null)
{
if (PropertyChanged != null)
{
syncContext.Post(_ => PropertyChanged(this, new PropertyChangedEventArgs("HttpResponse")), null);
syncContext.Post(_ => PropertyChanged(this, new PropertyChangedEventArgs("HttpContent")), null);
}
}
else
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("HttpResponse"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("HttpContent"));
}
}
}
}
11 changes: 6 additions & 5 deletions WinformRESTest/Gui/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@
using ReaLTaiizor.Forms;
using ReaLTaiizor.Manager;
using System;
using System.Threading;
using System.Windows.Forms;

namespace WinformRESTest;

public partial class MainForm : MaterialForm
{
private readonly RESTestCore.RESTestCore restTest = null;
private RESTestCore.RESTestCore restTest = null;

/// <summary>
/// Main form constructor
/// </summary>
public MainForm(ref RESTestCore.RESTestCore restTest)
public MainForm()
{
try
{
this.restTest = restTest;
restTest = new RESTestCore.RESTestCore(SynchronizationContext.Current);
InitializeComponent();

MaterialSkinManager.Instance.AddFormToManage(this);
Expand Down Expand Up @@ -72,7 +73,7 @@ private void materialComboBoxMethod_SelectedIndexChanged(object sender, EventArg
}
}

private void materialButtonTestApi_Click(object sender, EventArgs e)
private async void materialButtonTestApi_Click(object sender, EventArgs e)
{
try
{
Expand All @@ -88,7 +89,7 @@ private void materialButtonTestApi_Click(object sender, EventArgs e)

Properties.Settings.Default.Save();

restTest.Send();
await restTest.SendAsync();
}
catch (Exception except)
{
Expand Down
2 changes: 1 addition & 1 deletion WinformRESTest/Installer/Setup.iss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define MyAppName "RESTest"
#define MyAppVersion "1.0.0.0"
#define MyAppVersion "1.1.0.0"
#define MyAppPublisher "DevElkami"
#define MyAppURL "https://github.com/DevElkami/RESTest"
#define MyAppDescription "RESTest"
Expand Down
5 changes: 2 additions & 3 deletions WinformRESTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ static void Main()
MaterialSkinManager.Instance.EnforceBackcolorOnAllComponents = true;
MaterialSkinManager.Instance.Theme = MaterialSkinManager.Themes.LIGHT;

// Run app
RESTestCore.RESTestCore restTest = new();
Application.Run(new MainForm(ref restTest));
// Run app
Application.Run(new MainForm());
}
catch (Exception except)
{
Expand Down
4 changes: 2 additions & 2 deletions WinformRESTest/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]

0 comments on commit 05d8459

Please sign in to comment.