File installation/copy system

Asked

Viewed 94 times

4

How to use items

SortedDictionary
File.WriteAllBytes

to start or complete a file and folder installation process for the computer.

Ex:

File list:

void AlocarArquivos(){
var arquivo_e_pasta = new SortedDictionary<string, byte[]>();
arquivo_e_pasta.Add(@"\bin32\dedicated.exe", Properties.Resources.bin32_dedicated);
arquivos_e_pastas.Add(@"\sdk\player.df", Properties.Resources.PLAYER_DF_BTS);
}

And then go from one to one applying it:

var enum0 = arquivos_e_pastas.GetEnumerator();
while(enum0.MoveNext()){
    File.WriteAllBytes(enum0.Current.Key, enum0.Current.Value);
}

But only having the installation progress applying Thread.Sleep without crashing the application.

  • 2

    I doubt I need one SortedDictionary for this. You should give preference to the foreach. The problem with the question is that it’s too loose. It doesn’t have a context.

  • Nathan, please prefer it format your posts in Markdown. Use <pre><code>, the code does not render the language markup.

1 answer

0

how about creating a new Thread for this operation?

 new System.Threading.Thread((enum) => {
//Converta a enum para o objeto de sua preferencia...
var Enum = (var)enum;
while(Enum.MoveNext()){
    File.WriteAllBytes(Enum.Current.Key, Enum.Current.Value);
}}).Start(enum0);

In this algorithm a task will be started in a secondary thread, when executing this command the process will be done and the main thread (your program) will continue running... unfortunately the problem with this is that the program can start before this thread runs the algorithm... (In this case I recommend making a waiting algorithm in the Main class before starting the main form...)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.