MechWarrior99
MechWarrior99
CC#
Created by MechWarrior99 on 1/21/2024 in #help
How to safely access parameters from Task (Porting from Unity IJob)
I am making a program for generating a 3D mesh from parameters. The generation is done in some Tasks run with Task.Run. I'm struggling to grasp how to properly and safely access the parameters when generating. I am porting the system over from Unity's IJob system, which I think is sort of 'boxing' my thinking in making it hard to get my head around what I need to do. Do I make a class/struct that has all the parameters in it that I populate beforehand and use those values during generation? Sort of like Unity's Job system. Thanks 🙂
36 replies
CC#
Created by MechWarrior99 on 10/24/2023 in #help
❔ Cancel task on nested exception
I have a series of nested async methods, when a exception is thrown I want to cancel the task. The main issue is that I need to do a try cache in a for loop in a nested method, so that we can get more detailed telemetry about it. That means that the methods just keep going. I could pass the CTS to the tasks instead, or access it through other means, but that also feels a little messy. Hope this makes sense.
private CancellationTokenSource _tokenSource;
public async Task RunBigTask()
{
_tokenSource = new CancellationTokenSource();
// Some logic here...
await OtherClass.RunSmallerTasks(_tokenSource.Token);
// Some other logic here...
}

// In another class...
public async Task RunSmallerTasks(CancellationToken ct)
{
for(int i = 0; i < k; i++)
{
ct.ThrowIfCancellationRequested();
try
{
await RunSmallTask();
}
catch(Exception e)
{
// Sending telemetry here about the exception.
}
}
}
private CancellationTokenSource _tokenSource;
public async Task RunBigTask()
{
_tokenSource = new CancellationTokenSource();
// Some logic here...
await OtherClass.RunSmallerTasks(_tokenSource.Token);
// Some other logic here...
}

// In another class...
public async Task RunSmallerTasks(CancellationToken ct)
{
for(int i = 0; i < k; i++)
{
ct.ThrowIfCancellationRequested();
try
{
await RunSmallTask();
}
catch(Exception e)
{
// Sending telemetry here about the exception.
}
}
}
3 replies
CC#
Created by MechWarrior99 on 6/14/2023 in #help
❔ Cross-platform 3D rendering library?
Hello, I am working on an application/tool to generate 3D models. I was wondering if there was a good library for 3D rendering, and showing that in a UI. I know there is Silk.Net. But that seems a bit too low level for me (not a graphics/rendering guy at all). And on the other end, I also know that Avalonia has trouble showing 3D renders. Any suggestions to solve these issues? Would I be best to use a game engine like Godot, even if I would have to roll my own UI binding system, and don't need any of the other features a game engine has? Thanks!
7 replies
CC#
Created by MechWarrior99 on 8/18/2022 in #help
How does assigning default values when creating an instance work? [Answered]
I'm not sure how to ask this question. I also can't for the life of me remember what this style of instance creating is called, otherwise I would just look it up.
public interface IData
{
int Value { get; set; }
}
public class Data : IData
{
public int Value { get; set; }
}

public class Container
{
public IData DataSlot { get; set; }
}

// In some method...

var container = new Container()
{
// How does this work? DataSlot is a interface.
DataSlot = { Value = 5 }
}
public interface IData
{
int Value { get; set; }
}
public class Data : IData
{
public int Value { get; set; }
}

public class Container
{
public IData DataSlot { get; set; }
}

// In some method...

var container = new Container()
{
// How does this work? DataSlot is a interface.
DataSlot = { Value = 5 }
}
11 replies