nks1fu
nks1fu
CC#
Created by nks1fu on 4/8/2023 in #help
❔ ✅ Creating a console application in C# that utilizes async/await functions.
ty again
55 replies
CC#
Created by nks1fu on 4/8/2023 in #help
❔ ✅ Creating a console application in C# that utilizes async/await functions.
lol
55 replies
CC#
Created by nks1fu on 4/8/2023 in #help
❔ ✅ Creating a console application in C# that utilizes async/await functions.
and one more question do i need to close the post?
55 replies
CC#
Created by nks1fu on 4/8/2023 in #help
❔ ✅ Creating a console application in C# that utilizes async/await functions.
ty man
55 replies
CC#
Created by nks1fu on 4/8/2023 in #help
❔ ✅ Creating a console application in C# that utilizes async/await functions.
ty so muchh and have a nice day
55 replies
CC#
Created by nks1fu on 4/8/2023 in #help
❔ ✅ Creating a console application in C# that utilizes async/await functions.
i was worrying alot
55 replies
CC#
Created by nks1fu on 4/8/2023 in #help
❔ ✅ Creating a console application in C# that utilizes async/await functions.
thank you for the help
55 replies
CC#
Created by nks1fu on 4/8/2023 in #help
❔ ✅ Creating a console application in C# that utilizes async/await functions.
oh ok
55 replies
CC#
Created by nks1fu on 4/8/2023 in #help
❔ ✅ Creating a console application in C# that utilizes async/await functions.
do u think its good enough?
55 replies
CC#
Created by nks1fu on 4/8/2023 in #help
❔ ✅ Creating a console application in C# that utilizes async/await functions.
improve it like not making it dry
55 replies
CC#
Created by nks1fu on 4/8/2023 in #help
❔ ✅ Creating a console application in C# that utilizes async/await functions.
wanted to check all the boxes
55 replies
CC#
Created by nks1fu on 4/8/2023 in #help
❔ ✅ Creating a console application in C# that utilizes async/await functions.
wanted to see is there a way to make it better
55 replies
CC#
Created by nks1fu on 4/8/2023 in #help
❔ ✅ Creating a console application in C# that utilizes async/await functions.
i am just scared cuz staff is gonna check it with there own developer
55 replies
CC#
Created by nks1fu on 4/8/2023 in #help
❔ ✅ Creating a console application in C# that utilizes async/await functions.
i cant use that yet
55 replies
CC#
Created by nks1fu on 4/8/2023 in #help
❔ ✅ Creating a console application in C# that utilizes async/await functions.
namespace FileSizeCalculator
{
class Program
{
static async Task Main(string[] args)
{

Console.WriteLine("Enter directory paths separated by commas:");
string input = Console.ReadLine();
List<string> directoryPaths = new List<string>(input.Split(','));

long[] sizes = await GetTotalSizeAsync(directoryPaths);
long totalSize = sizes.Sum();


Console.WriteLine($"Total number of files: {GetFileCount(directoryPaths)}");
Console.WriteLine($"Total size of files (bytes): {totalSize}");
}
namespace FileSizeCalculator
{
class Program
{
static async Task Main(string[] args)
{

Console.WriteLine("Enter directory paths separated by commas:");
string input = Console.ReadLine();
List<string> directoryPaths = new List<string>(input.Split(','));

long[] sizes = await GetTotalSizeAsync(directoryPaths);
long totalSize = sizes.Sum();


Console.WriteLine($"Total number of files: {GetFileCount(directoryPaths)}");
Console.WriteLine($"Total size of files (bytes): {totalSize}");
}
55 replies
CC#
Created by nks1fu on 4/8/2023 in #help
❔ ✅ Creating a console application in C# that utilizes async/await functions.
the Task.WhenAll ?
55 replies
CC#
Created by nks1fu on 4/8/2023 in #help
❔ ✅ Creating a console application in C# that utilizes async/await functions.
55 replies
CC#
Created by nks1fu on 4/8/2023 in #help
❔ ✅ Creating a console application in C# that utilizes async/await functions.
static async Task<long> GetTotalSizeAsync(List<string> directoryPaths)
{
long totalSize = 0;


await Task.WhenAll(directoryPaths.Select(async directoryPath =>
{

string[] files = await Task.Run(() => Directory.GetFiles(directoryPath));
foreach (string file in files)
{
totalSize += await GetFileSizeAsync(file);
}
}));

return totalSize;
}

static int GetFileCount(List<string> directoryPaths)
{
int totalFileCount = 0;


foreach (string directoryPath in directoryPaths)
{

string[] files = Directory.GetFiles(directoryPath);
totalFileCount += files.Length;
}

return totalFileCount;
}
}
}
static async Task<long> GetTotalSizeAsync(List<string> directoryPaths)
{
long totalSize = 0;


await Task.WhenAll(directoryPaths.Select(async directoryPath =>
{

string[] files = await Task.Run(() => Directory.GetFiles(directoryPath));
foreach (string file in files)
{
totalSize += await GetFileSizeAsync(file);
}
}));

return totalSize;
}

static int GetFileCount(List<string> directoryPaths)
{
int totalFileCount = 0;


foreach (string directoryPath in directoryPaths)
{

string[] files = Directory.GetFiles(directoryPath);
totalFileCount += files.Length;
}

return totalFileCount;
}
}
}
55 replies
CC#
Created by nks1fu on 2/2/2023 in #help
❔ ✅ beginner class and properties
!close
55 replies
CC#
Created by nks1fu on 2/2/2023 in #help
❔ ✅ beginner class and properties
ty and have a nice day
55 replies