Steff
Steff
CC#
Created by Steff on 8/12/2024 in #help
✅ CancellationtokenSource and Cancel Task
A big, big thank you! You've solved pretty much every problem I have at the moment 😄
10 replies
CC#
Created by Steff on 8/12/2024 in #help
✅ CancellationtokenSource and Cancel Task
Without knowing the content, I have a small question that could actually answer everything for me: If I cancel a task with CancellationTokenSource, is the CancellationTokenSource then "used up" and I have to create a new CancellationTokenSource for the next task?
10 replies
CC#
Created by Steff on 7/25/2024 in #help
Queue Cancellationtoken
Thanks all 🙂 ❤️
35 replies
CC#
Created by Steff on 7/25/2024 in #help
Queue Cancellationtoken
oh shit. I am really stupid
35 replies
CC#
Created by Steff on 7/25/2024 in #help
Queue Cancellationtoken
I am new to this field so please excuse my ignorance. So i can delete [ObservableProperty] from the CancellationToken and delete CancallationTokenSource, right ?
35 replies
CC#
Created by Steff on 7/25/2024 in #help
Queue Cancellationtoken
So I will probably rewrite the entire service again But this is my Item Class:
public partial class Item : ObservableObject
{
[ObservableProperty]
public string fileName;

[ObservableProperty]
public Decimal progress;

[ObservableProperty]
public double totalBytes;

[ObservableProperty]
public Customer downloadCustomer;

[ObservableProperty]
public StatusDownloads status;

[ObservableProperty]
public CancellationToken cancellationToken;

[ObservableProperty]
public CancellationTokenSource cancellationTokenSource;
public partial class Item : ObservableObject
{
[ObservableProperty]
public string fileName;

[ObservableProperty]
public Decimal progress;

[ObservableProperty]
public double totalBytes;

[ObservableProperty]
public Customer downloadCustomer;

[ObservableProperty]
public StatusDownloads status;

[ObservableProperty]
public CancellationToken cancellationToken;

[ObservableProperty]
public CancellationTokenSource cancellationTokenSource;
35 replies
CC#
Created by Steff on 7/25/2024 in #help
Queue Cancellationtoken
public partial class Service : IService
{
#region private Variable

private Queue<Item> _downloadQueues = new Queue<Item>();

private CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();

private async Task Initialize(string traceID)
{
await ProcessQueueAsync(traceID);
}

#endregion

#region Konstruktor
public Service()
{
string traceID = EX.GetTraceID();
_ = Initialize(traceID);
}
#endregion

#region Methoden

public async Task AddToDownloadQueue(string traceID, Item item)
{
try
{
if (item is not null)
{
_downloadQueues.Enqueue(Item);
}
else
{
_logger.Error(traceID, $"AddToDownloadQueueAsync:: Item is null");
return;
}
}
catch (Exception ex)
{
_logger.Error(traceID, ex, $"AddDownloadToQueue:: ");
return;
}
}

public async Task CancelDownload()
{
_cancellationTokenSource.Cancel();
}

public async Task ProcessQueueAsync(string traceId)
{
while (!_cancellationTokenSource.IsCancellationRequested)
{
if (_downloadQueues.Count > 0)
{
try
{
_waitTaskEventHandler.WaitOne(Constants.WAIT_FOR_CHECKQUEUE_IN_MS);
while (_downloadQueues.TryDequeue(out Item? Item))
{

Task? task = client.Download(traceId, Item, Item.CancellationToken);
await Task.Delay(1000);
}
_waitTaskEventHandler.Reset();
}
public partial class Service : IService
{
#region private Variable

private Queue<Item> _downloadQueues = new Queue<Item>();

private CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();

private async Task Initialize(string traceID)
{
await ProcessQueueAsync(traceID);
}

#endregion

#region Konstruktor
public Service()
{
string traceID = EX.GetTraceID();
_ = Initialize(traceID);
}
#endregion

#region Methoden

public async Task AddToDownloadQueue(string traceID, Item item)
{
try
{
if (item is not null)
{
_downloadQueues.Enqueue(Item);
}
else
{
_logger.Error(traceID, $"AddToDownloadQueueAsync:: Item is null");
return;
}
}
catch (Exception ex)
{
_logger.Error(traceID, ex, $"AddDownloadToQueue:: ");
return;
}
}

public async Task CancelDownload()
{
_cancellationTokenSource.Cancel();
}

public async Task ProcessQueueAsync(string traceId)
{
while (!_cancellationTokenSource.IsCancellationRequested)
{
if (_downloadQueues.Count > 0)
{
try
{
_waitTaskEventHandler.WaitOne(Constants.WAIT_FOR_CHECKQUEUE_IN_MS);
while (_downloadQueues.TryDequeue(out Item? Item))
{

Task? task = client.Download(traceId, Item, Item.CancellationToken);
await Task.Delay(1000);
}
_waitTaskEventHandler.Reset();
}
35 replies
CC#
Created by Steff on 11/4/2023 in #help
Encrypt password
If it works the way I want it to in the end, it will be perfect! 😄 But thank you very much ❤️ 🙂
18 replies
CC#
Created by Steff on 11/4/2023 in #help
Encrypt password
Thanks for help ❤️
18 replies
CC#
Created by Steff on 11/4/2023 in #help
Encrypt password
So i can this use for WPF?
18 replies
CC#
Created by Steff on 11/4/2023 in #help
Encrypt password
Oh, then I apologize for that 😄
18 replies
CC#
Created by Steff on 11/4/2023 in #help
Encrypt password
Let me not get this wrong. Don't I have to make sure that my passwords are stored securely in the database and cannot be accessed "blank"? Or am I just getting this wrong
18 replies
CC#
Created by Steff on 10/11/2022 in #help
HTTP Post query
oh, thanks 🙂
23 replies
CC#
Created by Steff on 10/11/2022 in #help
HTTP Post query
Thanks ! ❤️
23 replies
CC#
Created by Steff on 10/11/2022 in #help
HTTP Post query
so?
var result = await client.PostAsync("https://ptsv2.com/t/" + textBox1.Text + "/post", load).Result.Content.ReadAsStringAsync();
var result = await client.PostAsync("https://ptsv2.com/t/" + textBox1.Text + "/post", load).Result.Content.ReadAsStringAsync();
23 replies
CC#
Created by Steff on 10/11/2022 in #help
HTTP Post query
yes, await
23 replies
CC#
Created by Steff on 10/11/2022 in #help
HTTP Post query
Wait
23 replies
CC#
Created by Steff on 10/11/2022 in #help
HTTP Post query
oh
23 replies
CC#
Created by Steff on 10/11/2022 in #help
HTTP Post query
var result = client.PostAsync("https://ptsv2.com/t/" + textBox1.Text + "/post", load).Result.Content.ReadAsStringAsync().Result;
var result = client.PostAsync("https://ptsv2.com/t/" + textBox1.Text + "/post", load).Result.Content.ReadAsStringAsync().Result;
23 replies
CC#
Created by Steff on 10/11/2022 in #help
HTTP Post query
Yeah, I already did that.
23 replies