eid
await-work in thread class is different from await-work in task class?
var thread = new Thread(async () =>
{
Console.WriteLine($"Thread before await: {Thread.CurrentThread.ManagedThreadId}");
await Task.Delay(500); // Simulate asynchronous delay
Console.WriteLine($"Thread after await: {Thread.CurrentThread.ManagedThreadId}");
});
thread.Start();
thread.Join(); // Wait for the thread to complete
// Using Task
Task.Run(async () =>
{
Console.WriteLine($"Task before await: {Thread.CurrentThread.ManagedThreadId}");
await Task.Delay(500); // Simulate asynchronous delay
Console.WriteLine($"Task after await: {Thread.CurrentThread.ManagedThreadId}");
}).Wait(); // Wait for the task to complete
4 replies
✅ CancellationTokenSource .. apply what design pattern?
i notice it's object wrap other object(cancellation-token),to prevent it to set its flag in the background threads,and it is the responsible for manage it(cancel it by set it true,callback method,timeout method,etc),
what the name of that design in c#?
2 replies
svelte with asp.net core
I don't know why svelte not popular with asp.net core, i see it very easy and similar to blazor and overcome on the problem of blazor,
i can't find book that talk about svelte with asp.net core , if u know a book that talk about that , please tell me about it
37 replies
Application.DoEvents method in winform, can't understand it, any one can explain it?
This deadlock, in its general
form – UI waiting for something that is waiting for UI – has existed ever since we started making
UI applications; it predates async-await, it predates .net and C#, it even predates asynchronous
IO in the Windows operating system. And so, unsurprisingly, there is a standard solution for this
problem already built into WinForms (and WPF and all other UI frameworks I know about). This
solution is to let the UI handle events (or “pump messages” in Windows API terminology) while
we are waiting for the background task to complete. In WinForms, we do this by calling the
Application.DoEvents method.
private void button1_Click(object sender, EventArgs ea)
{
var task = DoSomething();
while(!task.IsCompleted)#A
Application.DoEvents();#A
label1.Text = task.Result;
}
private async Task<string> DoSomething()
{
await Task.Delay(500)
return "done";
20 replies
can any one explain that?
Why is functor not an interface?
If both Option and IEnumerable support the Map operation, why are we not capturing
this with an interface? Indeed, it would be nice to do so, but unfortunately, it’s not possible in
C#. To illustrate why, let’s try to define such an interface:
interface Functor<F<>, T>
{
F<R> Map<R>(Func<T, R> f);
}
public struct Option<T> : Functor<Option, T>
{
public Option<R> Map<R>(Func<T, R> f) => // ...
}
This doesn’t compile: we can’t use F<> as a type variable because unlike T, it doesn’t indicate
a type but rather a kind: a type that’s, in turn, parameterized with a generic type. And it’s not
enough for Map to return a Functor. It must return a functor of the same kind as the current
instance
6 replies
i'm learning the functional programming with c#, i'm trying to use :validation<Exceptional<double>>
any one know about that type which it is alternative to either type.
my question how to use that type, that is my trial , the invalid part is confusing with me.
Validation<Exceptional<double>> calc3(double x, double y)=>y==0?Invalid(new Error("please use num less that 10")):Valid(Exceptional(x/y));
6 replies
❔ How i can solve that in entityframworkcore
Unhandled exception. Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details.
---> Microsoft.Data.SqlClient.SqlException (0x80131904): The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Employees_Departments_DepartmentID". The conflict occurred in database "secondbase", table "dbo.Departments", column 'DepartmentID'.
14 replies
✅ dotnet ef scaffold problem
dotnet ef dbcontext scaffold problem
dotnet ef dbcontext scaffold 'Server=localhost;Database=secondbase;User Id=sa;Password=rereouiuf111!;Encrypt=True;' Microsoft.EntityFrameworkCore.SqlServer
Build started...
Build succeeded.
connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)
4 replies
❔ EF Core Power Tools for vscode
i'm using linux , so i can't use vs community on it, so i'm using vscode, now i'm learning ef core, i need to do database first approach(covert database to model code) , i found there is gui way to do that by that extension(ef core power tools) but that available for vs community, my question there is gui extension in vscode can do that, or there is any gui tool or program do that in linux??
4 replies