UWP C# Faster checking.

VoyTec 671 Reputation points
2021-10-25T20:11:56.093+00:00

Greeting dear M Comunnity.

I wanted to ask if there is faster way to check if a file contais anything else except "" just checking the file kb
I use this code for now:

for (int x = 1; x < 32; x++)
            {
                for (int l = 1; l < 321; l++)
                {
                    string data = "";
                    if (x > 9) { data = $"{x}.01.2022"; }
                    if (x < 10) { data = $"0{x}.01.2022"; }

                    StorageFolder folderSP = await KnownFolders.DocumentsLibrary.GetFolderAsync("Św. Puszcza App");
                    try { StorageFolder folderDATA = await folderSP.GetFolderAsync(data); }
                    catch { Windows.Storage.StorageFolder folderDATA = await folderSP.CreateFolderAsync(data, CreationCollisionOption.ReplaceExisting); }
                    StorageFolder nowyfolderDATA = await folderSP.GetFolderAsync(data);
                    try { StorageFile plik = await nowyfolderDATA.GetFileAsync(l + ".dat"); }
                    catch { Windows.Storage.StorageFile plik = await nowyfolderDATA.CreateFileAsync(l + ".dat", CreationCollisionOption.ReplaceExisting); }
                    Windows.Storage.StorageFile plikPOKOJ = await nowyfolderDATA.GetFileAsync(l + ".dat");
                    string text = await Windows.Storage.FileIO.ReadTextAsync(plikPOKOJ);

                    pasek_ladowania.Value = pasek_ladowania.Value + 0.0493;
                    // 01
                    if (x == 1)
                    {
                        if ((l == 1) && (text == "")) { _2_os.Text = _2_os.Text + " " + l + ","; 
...
}
Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. VoyTec 671 Reputation points
    2021-11-02T17:41:39.767+00:00

    @Nico Zhu (Shanghai Wicresoft Co,.Ltd.)

    private async void check()  
    {  
    loading_bar.Value = 0;  
    var tasks = new List<Task>();  
    for (int days = 1; days < 32; days++)  
    {  
    tasks.Add(Task.Run(async () =>  
    {  
    await Task.Delay(TimeSpan.FromSeconds(0.01));  
    for (int room = 1; room < 321; room++)  
    {  
    loading_bar.Value = loading_bar.Value + 0.0493;  
    string date = "";  
    if (x > 9) { date = $"{x}.01.2022"; }  
    if (x < 10) { date = $"0{x}.01.2022"; }  
    StorageFolder folderApp = await KnownFolders.DocumentsLibrary.GetFolderAsync("My Application");  
    try { StorageFolder folderDATE = await folderApp.GetFolderAsync(data); }  
    catch { Windows.Storage.StorageFolder folderDATE = await folderApp.CreateFolderAsync(data, CreationCollisionOption.ReplaceExisting); }  
    StorageFolder newfolderDATE = await folderApp.GetFolderAsync(data);  
    try { StorageFile file = await newfolderDATE.GetFileAsync(room + ".dat"); }  
    catch { Windows.Storage.StorageFile file = await newfolderDATE.CreateFileAsync(room + ".dat", CreationCollisionOption.ReplaceExisting); }  
    Windows.Storage.StorageFile fileROOM = await newfolderDATE.GetFileAsync(room + ".dat");  
    string text = await Windows.Storage.FileIO.ReadTextAsync(fileROOM);  
    if (days == 1)  
    {  
    if ((room == 1) && (text == "")) { room4two.Text = room4two.Text + " " + room + ","; }  
    if ((room == 2) && (text == "")) { room4two.Text = room4two.Text + " " + room + ","; }  
    etc...blah blah blah.,..  
    }  
    }  
    }));  
    }    
    Task t = Task.WhenAll(tasks);  
    loading_bar.Visibility = Visibility.Collapsed;  
    }  
    

    App is for calculating and showing available rooms from checking all room files from saved data.
    Problem: not calculating or not showing anything.