Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
static    public void getSize(string pathLocation)
{

    DirectoryInfo dInfo = new DirectoryInfo(pathLocation);
    sizeOfDirKb = DirectorySize(dInfo, true) / (1024);


    adminProcess = new System.Diagnostics.ProcessStartInfo();

    TotalSizeOfFolderByte = sizeOfDirKb / (1024 * 1024);

    if (TotalSizeOfFolderByte < 100)
    {
        TotalSizeOfFolder = Math.Floor(TotalSizeOfFolderByte * 100) / 100;

    }
    else if (TotalSizeOfFolderByte >= 100)
    {
        TotalSizeOfFolder = Math.Floor(TotalSizeOfFolderByte);
    }
}

static int i=0;

static   double DirectorySize(DirectoryInfo dInfo, bool includeSubDir)
{
    totalSize = dInfo.EnumerateFiles()//double
                .Sum(file => file.Length);//double
    Total = Total + totalSize / 1024 / 1024 / 1024;//double
    total1[i] = Total;//double

    if (includeSubDir)
    {
        totalSize += dInfo.EnumerateDirectories()
                 .Sum(dir => DirectorySize(dir, true));

    }

    return totalSize;
}


What I have tried:

Multi thread and multi task but still can not.
Posted
Updated 2-Dec-19 5:26am
v4
Comments
CHill60 2-Dec-19 8:19am    
You have not stated the question or a problem. Please use the "Improve question" link to add this detail to your post
Tra22 2-Dec-19 9:29am    
Could I have your email or telegram for send it to u and easy to dicuss?
CHill60 2-Dec-19 10:11am    
No, you may not.
Tra22 2-Dec-19 10:12am    
So now u understand what I mean?
Tra22 2-Dec-19 10:20am    
Where can I ask it? Thank beforehand that explain me.

Windows Forms has the fewest short-cuts to threading; this should help:

C# Corner: Multithreading in WinForms -- Visual Studio Magazine[^]
 
Share this answer
 
Comments
Tra22 2-Dec-19 11:07am    
Yeah bro. But I try it already but when I apply it to my function it doesn't work. When I get thread to array and run it with function with loop. It doesn't work.
[no name] 2-Dec-19 11:20am    
Try harder.
CHill60 2-Dec-19 11:47am    
"it doesn't work" does not help us to help you. You are really making this hard work for us
Tra22 2-Dec-19 19:40pm    
Why?
CHill60 3-Dec-19 5:37am    
Why? Because you are not being clear about your problem. You need to learn to describe problems accurately and fully. It's hard work for us to keep asking you questions and asking for clarification. Most people will just stop bothering.
Luckily, it looks like Ashutosh is helping you along now.
getsize for multiple path location at same time, use c# inbuilt TPL(parallel task library)
Parallel.Invoke(
            () =>
            {
                //code for getsize1
            },

            () =>
            {
                //code for getsize2
            },

            () =>
            {
                //code for getsizeN
            }

i hope this will help.
 
Share this answer
 
Comments
Tra22 2-Dec-19 18:14pm    
Could we use loop on parallel. Invoke? Because the function getSize is alot and we can not know how much is it.
Tra22 2-Dec-19 18:25pm    
Mean that the location path for get size store in arraylist
[no name] 3-Dec-19 0:34am    
something like below
var collectionofpaths = new List<string>();
var actions = new List<action>();
foreach (var path in collectionofpaths)
{
actions.Add(() => getsize(path));
}

Parallel.Invoke(actions.ToArray());
Tra22 3-Dec-19 5:13am    
I will try it.And tell you about it can or not.Too much thanks bro.
Tra22 3-Dec-19 5:45am    
The problems is that the function is not calculate one by one.But it's total all size of function.Example getSize1=100GB ,getSize2=1000Gb,getSize3=10000GB but it's not show like that.But it shows with 11100GB(Total all function)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900