C
C#CrosRoad95

❔ Making an async method without anything to async inside

let's say i have following scenario:
void Foo()
{
for(int i = 0 ; i < 10000000 ;i++){} // simulate load
}
void Foo()
{
for(int i = 0 ; i < 10000000 ;i++){} // simulate load
}
the following method is blocking, but also don't have anything that can await inside. how can i turn this example into async Task Foo()?
C
CrosRoad95511d ago
seen some people were using Task.FromResult that i don't understand how it works at least i can run this task and maybe await later
async Task Foo()
{
await Task.Run(() => {
for(int i = 0 ; i < 10000000 ;i++){}
});
}
async Task Foo()
{
await Task.Run(() => {
for(int i = 0 ; i < 10000000 ;i++){}
});
}
is it okey to do like this? how? 😄 ^ but stacktrace will be wrong watched nick chapsas and he said returning a task without awaitng is not very good idea
H
Hin511d ago
Haven't really used but there is Parallel.For Maybe that will help if you want it to be parallel
A
Accord510d ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ Reading file from the folder where .csproj isHow can i read files from folder where .csproj is? just like webapps allow to do, they do not copy f✅ Interoperability between incompatible typesHi! I'm trying to pass a class back-and-forth from C# to CPP. This class contains some members that ❔ Set item to null inside a listHey! I am trying to remove some items from a JSON object (created like `var model = new ObjectModel{Refactoring long if statement that checks for user rolesHi, I'm trying to find a cleaner way of refactoring this if code block that checks for each user rol❔ IEnumerable and dependency injectionif i want to loop enumerable from DI multiple times ``` var foos = services.GetRequiredService<IEnum❔ How did you learn . NET ?Books /youtube/udemy /other courses, what resources made you learn .NET to use as your job as web de✅ Is it possible to disable these properties on EF6? Web API 2 project, multi-layered, NF472SCENARIO - Solution type is NET Framework 4.7.2 (it is, what it is). - I have this project, I'm cons✅ This EntityFramework query can not be translated for SQLiteThe issue lies within `Intersect`. The point of the query is to fetch the current user, and to popul✅ Detect Network RequestI want make service that detect all connection to specific domain or ip? And if this request contain❔ CORS errorHello, I have Cors error on my project. I add Addpolicy in my configureServices and also add app.Us❔ Ambiguities? How?Idk how i can resolve this i don't see the problem✅ How can I get rid of this annoying pointer thing in the first row, datagridview winforms^✅ How can I use a row header of a datagridview to display the row number instead of being empty?^✅ How can i properly display this datagridviewHow can i get rid of the row select thing on the left (just white space)✅ I am trying to output a 2D array to a datagridview, but it is not outputting correctlyIt is saying System.Int32[]✅ Task not returning and stopping programHey, I am currently trying to start one task for every string in the list, but this isn't working an❔ DbContextCan i use this in a non-asp area like for example, a simple program to make few tables using DbSet✅ The specified deps.json does not exist while scaffolding DBI am going through a tutorial to create a Web API app with ASP.NET6 and MySql. I wanted to scaffold ❔ C sharp object reference errorI am trying to reference an object that I'm displaying on PageHeader.xaml and I keep getting this erInteroperability issues (PInvoke)Hi! I'm calling a native CPP library and retrieving a struct by reference which returns a struct con