Shinigami
Shinigami
CC#
Created by Shinigami on 8/24/2024 in #help
Why does Task 1 prints first instead of Task 3 - Async & Await
internal class Program
{
private static async Task Main(string[] args)
{
Task firstTask = Task.Run(async ()=> {
// Thread.Sleep(1000);
await Task.Delay(10000);
Console.WriteLine("Task 1");
});
// firstTask.Start();
// Console.WriteLine("YOYOYOY");
await firstTask;

Task secondTask = ConsoleWithDelayAsync("Task 2",150);
Task thirdTask = ConsoleWithDelayAsync("Task 3",9);
Task fourthTask = ConsoleWithDelayAsync("Task 4",80);

await secondTask;
await thirdTask;
await fourthTask;
}

public static void ConsoleWithDelay(string text, int delay){
Thread.Sleep(delay);
Console.WriteLine(text);
}

public static async Task ConsoleWithDelayAsync(string text, int delay){
await Task.Delay(delay);
Console.WriteLine(text);
}
}
internal class Program
{
private static async Task Main(string[] args)
{
Task firstTask = Task.Run(async ()=> {
// Thread.Sleep(1000);
await Task.Delay(10000);
Console.WriteLine("Task 1");
});
// firstTask.Start();
// Console.WriteLine("YOYOYOY");
await firstTask;

Task secondTask = ConsoleWithDelayAsync("Task 2",150);
Task thirdTask = ConsoleWithDelayAsync("Task 3",9);
Task fourthTask = ConsoleWithDelayAsync("Task 4",80);

await secondTask;
await thirdTask;
await fourthTask;
}

public static void ConsoleWithDelay(string text, int delay){
Thread.Sleep(delay);
Console.WriteLine(text);
}

public static async Task ConsoleWithDelayAsync(string text, int delay){
await Task.Delay(delay);
Console.WriteLine(text);
}
}
The output I'm getting is Task 1 Task 3 Task 4 Task 2 Aren't all the Tasks async above? So while Task 1 waits for 10 secs should the rest of the code continue?
46 replies
CC#
Created by Shinigami on 11/17/2023 in #help
✅ ValidationContext in ASP.NET
What does ObjectInstance and ObjectType mean? afaik 1) ValidationContext is basically on which class the validation is performed. 2) ObjectInstance is where we have all the values for a model class 3) I'm not sure what object type is. What does this code do here?
PropertyInfo? otherproperty = validationContext.ObjectType.GetProperty(PropertyName);

DateTime from_date = Convert.ToDateTime(otherproperty.GetValue(validationContext.ObjectInstance));
PropertyInfo? otherproperty = validationContext.ObjectType.GetProperty(PropertyName);

DateTime from_date = Convert.ToDateTime(otherproperty.GetValue(validationContext.ObjectInstance));
I'm trying to fetch a different property value from in the same model class Model class
//Multiple Properties using Reflection
public string? FromDate { get; set; }

[DateRangeValidator("FromDate", ErrorMessage = "From Date should be less than To Date.")]
public string? ToDate { get; set; }
//Multiple Properties using Reflection
public string? FromDate { get; set; }

[DateRangeValidator("FromDate", ErrorMessage = "From Date should be less than To Date.")]
public string? ToDate { get; set; }
31 replies
CC#
Created by Shinigami on 10/11/2023 in #help
❔ WinForms Topmost property not working as intended.
Hi, I've create a basic forms app which will block the user's screen, the app's window state is maximized, and top most property is set to true. When i try to do alt tab, I'm able to switch to other applications sometimes and some times I'm not able to switch as intended. What could be the issue causing this inconsistency?
10 replies
CC#
Created by Shinigami on 9/28/2023 in #help
✅ why IActionResult and why not ActionResult?
It's recommended to use IActionResult as the return type when we are returning any action method, but why are we using the interface? Why not just ActionResult? I've also seen while returning a dictionary we use IDictionary as the return type, why is it like this? I know interfaces contain definition of methods which has to be implemented when inherited by a class.
129 replies
CC#
Created by Shinigami on 9/27/2023 in #help
❔ Two Routes redirecting to each other using RedirectToActionResult, what will happen in this case?
No description
10 replies
CC#
Created by Shinigami on 9/12/2023 in #help
✅ What is the best way to store basic C#?
Hi, I'm testing my C# code and learning from it. For example deserializing and serializing JSON using system.text.json, I have the working code in program.cs. Now i want to store it in a folder preferably same vscode folder to review it in future and test some other code. What's the best way to do it?
67 replies
CC#
Created by Shinigami on 8/16/2023 in #help
❔ Concepts to know for 2year experience on C# and .Net.
Hi, I have worked on winforms to create few desktop apps and created few APIs using C# and a crud webapp from YouTube with Entity framework. What do you think are the concepts/knowledge a person who posses with 2 years of experience in C# and .NET? I'm planning to skill up myself and any guidance is appriciated.
73 replies
CC#
Created by Shinigami on 6/1/2023 in #help
✅ best way to snooze winforms
I have a win forms app with a snooze button, once the snooze button is clicked i need to make the form disappear and make it appear after 30 mins and rn I'm doing a form.hide and thread.sleep(30 mins in millisecs). Is this the right way or is there anything else i can do here?
17 replies
CC#
Created by Shinigami on 5/3/2023 in #help
❔ how to make web api accessible from another machine
Hi, I've made a simple api which returns "hi, name" when i pass in name=rob. Now it's in localhost and i can only use in my host machine. How do i make the api available such that i cam access it from anywhere?
10 replies
CC#
Created by Shinigami on 4/3/2023 in #help
❔ WinForms WebView2 pop up window exposes task bar issue
Hi, I'm building a forms application where I've integrated WebView2 and the source url is e learning portal, where user can do trainings. I've kept the form fullscreen and topmost so that user is forced to complete them. But the issue is the trainings in the e learning portal open a pop up window, when this happens webview2 is focused on that pop up window and the task bar is visible. This can lead to user killing the application.
5 replies