Checking string with custom format in c# - c#

I'm creating a command system for my application but i don't know how to make c# recognize a pattern in my string.
Example:
add(variable1, variable2)
How to make c# recognize addUser(...) and do some stuff?
I'm currently using string contains but if user type add()()()()() or add((((((, it still work!
Please help!
sorry about my english!

This may not be perfect, but might give you some ideas :)
static void Main(string[] args)
{
string example_input = "xxxxx Add(user1, user2) xxxxxx";
string myArgs = getBetween2(example_input, "Add(", ")"); //myArgs = "user1, user2"
if (myArgs != "EMPTY")
{
myArgs = myArgs.Replace(" ", ""); // remove spaces... myArgs = "user1,user2"
string[] userArray = myArgs.Split(',');
foreach (string user in userArray)
{
Console.WriteLine(user);
//Your code here
}
}
Console.ReadKey(); //pause
}
static string getBetween2(string strSource, string strStart, string strEnd)
{
try
{
int Start, End;
if (strSource.Contains(strStart) && strSource.Contains(strEnd))
{
Start = strSource.IndexOf(strStart, 0) + strStart.Length;
End = strSource.IndexOf(strEnd, Start);
return strSource.Substring(Start, End - Start);
}
else
{
return "EMPTY";
}
}
catch
{
return "EMPTY";
}
}

Related

How to format a fixed length string

I have a fixed length string ABCDEFGHIJK, is there a way to convert this into AB-CDEFGHIJ-K using string format?
var s = "ABCDEFGHIJK";
Console.WriteLine($"{s[..2]}-{s[2..10]}-{s[^1..]}");
I have a fixed length string ABCDEFGHIJK, is there a way to convert
this into AB-CDEFGHIJ-K using string format?
Focusing on the "string format" part, we can implement IFormatProvider. This will format the string if it is EXACTLY eleven characters long, otherwise it just returns the same string back. Following the example, the "H" format stands for "hypenated":
private void button1_Click_2(object sender, EventArgs e)
{
string input = "ABCDEFGHIJK";
string output = String.Format(new MyStringFormat(), "Formatted: {0:H}", input);
Console.WriteLine(input);
Console.WriteLine(output);
}
public class MyStringFormat : IFormatProvider, ICustomFormatter
{
object IFormatProvider.GetFormat(Type formatType)
{
if (formatType == typeof(ICustomFormatter))
{
return this;
}
else
{
return null;
}
}
string ICustomFormatter.Format(string format, object arg, IFormatProvider formatProvider)
{
if (arg.GetType() != typeof(String))
{
try
{
return HandleOtherFormats(format, arg);
}
catch (FormatException e)
{
throw new FormatException(String.Format("The format of '{0}' is invalid.", format), e);
}
}
string ufmt = format.ToUpper(CultureInfo.InvariantCulture);
if (ufmt != "H")
{
try
{
return HandleOtherFormats(format, arg);
}
catch (FormatException e)
{
throw new FormatException(String.Format("The format of '{0}' is invalid.", format), e);
}
}
string result = arg.ToString();
if (result.Length != 11)
return result;
else
return result.Insert(2, "-").Insert(11, "-"); // see comment by Hans Passant!
}
private string HandleOtherFormats(string format, object arg)
{
if (arg is IFormattable)
return ((IFormattable)arg).ToString(format, CultureInfo.CurrentCulture);
else if (arg != null)
return arg.ToString();
else
return String.Empty;
}
}
howabout
var newstring = String.format("{0}-{1}-{2}", s.Substring(0,2), s.Substring(3,7), s.Substring(10,1))
you could also use interpolation and the new range stuff
var f = Regex.Replace("ABCDEFGHIJK", "^(..)(.*)(.)$", "$1-$2-$3");
...yeah, I know.
Also, dropping the {2}, etc. was inspired by Yuriy's answer here.
The Rube Goldberg way perhaps:
static void Main(string[] args)
{
string code = "ABCDEFGHIJK";
string mask = "##-########-#";
Console.WriteLine(code.Format(mask));
// AB-CDEFGHIJ-K
}
public static string Format(this string code, string mask, char token = '#')
{
StringBuilder sb = new StringBuilder(mask.Length);
int index = 0;
foreach (var item in mask)
{
if (item==token)
{
sb.Append(code[index++]);
}
else
{
sb.Append(item);
}
}
return sb.ToString();
}
Edit 1
replaced the space ' ' character placeholder with the pound sign '#' for better clarity.

Finding game launcher executables in directory C#

I'm trying to find executable files for games; however some are nested (For example Ark: Survival Evolved) (A:\Steam Games\steamapps\common\ARK\ShooterGame\Binaries\Win64\ShooterGame.exe)
I've spent ages trying to find a way to only find the executables which are relevant.
This link shows games when we don't search recursively. It finds most, but not all .exe's
This link shows games searching recursively, but also shows a bunch of binaries/redist exes.
Initially I tried excluding "bin","binary","binaries","redist" folders but that then didn't give me Ark: Survival Evolved for example.
I also considered filtering the .exe's based on their size, but Aperture Tag has a QC_Eyes.exe at 3055KB, but Tomb Raider II.exe is 892KB.
Here's the method I'm using to find the steam installation directory, and check the libraryfolders.vdf file for where the library locations are. For now I'm just writing to console so that I can see what the outputs are.
If anyone has any tips on how I can find the right files for the right games it would be much appreciated. Thanks
public void SearchSteam()
{
steamGameDirs.Clear();
string steam32 = "SOFTWARE\\VALVE\\";
string steam64 = "SOFTWARE\\Wow6432Node\\Valve\\";
string steam32path;
string steam64path;
string config32path;
string config64path;
RegistryKey key32 = Registry.LocalMachine.OpenSubKey(steam32);
RegistryKey key64 = Registry.LocalMachine.OpenSubKey(steam64);
foreach(string k32subKey in key32.GetSubKeyNames())
{
using (RegistryKey subKey = key32.OpenSubKey(k32subKey))
{
steam32path = subKey.GetValue("InstallPath").ToString();
config32path = steam32path + "/steamapps/libraryfolders.vdf";
if (File.Exists(config32path))
{
string[] configLines = File.ReadAllLines(config32path);
foreach(var item in configLines)
{
Console.WriteLine("32: " + item);
}
}
}
}
foreach(string k64subKey in key64.GetSubKeyNames())
{
using (RegistryKey subKey = key64.OpenSubKey(k64subKey))
{
steam64path = subKey.GetValue("InstallPath").ToString();
config64path = steam64path + "/steamapps/libraryfolders.vdf";
string driveRegex = #"[A-Z]:\\";
if (File.Exists(config64path))
{
string[] configLines = File.ReadAllLines(config64path);
foreach (var item in configLines)
{
Console.WriteLine("64: " + item);
Match match = Regex.Match(item, driveRegex);
if(item != string.Empty && match.Success)
{
string matched = match.ToString();
string item2 = item.Substring(item.IndexOf(matched));
item2 = item2.Replace("\\\\", "\\");
steamGameDirs.Add(item2);
}
}
steamGameDirs.Add(steam64path + "\\steamapps\\common\\");
}
}
}
foreach(string item in steamGameDirs)
{
string GameTitle;
string[] Executables = new string[0];
string[] steamGames = Directory.GetDirectories(item);
foreach (var dir in steamGames)
{
string title = dir.Substring(dir.IndexOf("\\common\\"));
string[] titlex = title.Split('\\');
title = titlex[2].ToString();
GameTitle = title;
Console.WriteLine("Title: " + GameTitle);
Console.WriteLine("Directory: " + dir);
string[] executables = Directory.GetFiles(dir, "*.exe", SearchOption.AllDirectories);
int num = 0;
foreach (var ex in executables)
{
//add "ex" to Executables[] if poss
Console.WriteLine(ex);
num++;
}
}
}
}
I've managed to do what I can, so first I detect where steam is installed through the registry, then I check /steamapps/libraryfolders.vdf for where the users libraries are, then check those libraries for any "top level" executables. The program then lets the user select their own exe if one isn't found in the top directory.
Seems like the best solution for now as the steamfiles module isn't currently active.
public void SearchSteam()
{
steamGameDirs.Clear();
string steam32 = "SOFTWARE\\VALVE\\";
string steam64 = "SOFTWARE\\Wow6432Node\\Valve\\";
string steam32path;
string steam64path;
string config32path;
string config64path;
RegistryKey key32 = Registry.LocalMachine.OpenSubKey(steam32);
RegistryKey key64 = Registry.LocalMachine.OpenSubKey(steam64);
if (key64.ToString() == null || key64.ToString() == "")
{
foreach (string k32subKey in key32.GetSubKeyNames())
{
using (RegistryKey subKey = key32.OpenSubKey(k32subKey))
{
steam32path = subKey.GetValue("InstallPath").ToString();
config32path = steam32path + "/steamapps/libraryfolders.vdf";
string driveRegex = #"[A-Z]:\\";
if (File.Exists(config32path))
{
string[] configLines = File.ReadAllLines(config32path);
foreach (var item in configLines)
{
Console.WriteLine("32: " + item);
Match match = Regex.Match(item, driveRegex);
if (item != string.Empty && match.Success)
{
string matched = match.ToString();
string item2 = item.Substring(item.IndexOf(matched));
item2 = item2.Replace("\\\\", "\\");
item2 = item2.Replace("\"", "\\steamapps\\common\\");
steamGameDirs.Add(item2);
}
}
steamGameDirs.Add(steam32path + "\\steamapps\\common\\");
}
}
}
}
foreach(string k64subKey in key64.GetSubKeyNames())
{
using (RegistryKey subKey = key64.OpenSubKey(k64subKey))
{
steam64path = subKey.GetValue("InstallPath").ToString();
config64path = steam64path + "/steamapps/libraryfolders.vdf";
string driveRegex = #"[A-Z]:\\";
if (File.Exists(config64path))
{
string[] configLines = File.ReadAllLines(config64path);
foreach (var item in configLines)
{
Console.WriteLine("64: " + item);
Match match = Regex.Match(item, driveRegex);
if(item != string.Empty && match.Success)
{
string matched = match.ToString();
string item2 = item.Substring(item.IndexOf(matched));
item2 = item2.Replace("\\\\", "\\");
item2 = item2.Replace("\"", "\\steamapps\\common\\");
steamGameDirs.Add(item2);
}
}
steamGameDirs.Add(steam64path + "\\steamapps\\common\\");
}
}
}
}
Attached the code so others can see how I've done it. I know it's not the best but it's working
The keydata seems to be in the appinfo.vdf file. So a somewhat working code to get the correct EXE file for steam games is as follows. Where the game is an EA game with a pointer to an URL or there is no data in the appinfo.vdf a fallback to your previous solution could be used. If anyone got a good parser of the appinfo.vdf the code would be better and not as hacky as the "IndexOf" solution.
GetSteamPath() in the below code can be updated to fetch from registry.
I am going to use that code to fix those petchy steam links that goes back to that anonymous globe-url icon.
(Written in .Net 5.0 - seems IndexOf for .4.7.2 is quirky. doesnt like \x00 I think)
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
namespace SteamAppsParser
{
class Program
{
static void Main(string[] args)
{
var libs = GetSteamLibs();
var apps = GetSteamApps(libs);
}
static List<AppInfo> GetSteamApps(List<string> steamLibs)
{
var apps = new List<AppInfo>();
foreach (var lib in steamLibs)
{
var appMetaDataPath = Path.Combine(lib, "SteamApps");
var files = Directory.GetFiles(appMetaDataPath, "*.acf");
foreach (var file in files)
{
var appInfo = GetAppInfo(file);
if (appInfo != null)
{
apps.Add(appInfo);
}
}
}
return apps;
}
static AppInfo GetAppInfo(string appMetaFile)
{
var fileDataLines = File.ReadAllLines(appMetaFile);
var dic = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (var line in fileDataLines)
{
var match = Regex.Match(line, #"\s*""(?<key>\w+)""\s+""(?<val>.*)""");
if (match.Success)
{
var key = match.Groups["key"].Value;
var val = match.Groups["val"].Value;
dic[key] = val;
}
}
AppInfo appInfo = null;
if (dic.Keys.Count > 0)
{
appInfo = new AppInfo();
var appId = dic["appid"];
var name = dic["name"];
var installDir = dic["installDir"];
var path = Path.GetDirectoryName(appMetaFile);
var libGameRoot = Path.Combine(path, "common", installDir);
if (!Directory.Exists(libGameRoot)) return null;
appInfo.Id = appId;
appInfo.Name = name;
appInfo.Manifest = appMetaFile;
appInfo.GameRoot = libGameRoot;
appInfo.InstallDir = installDir;
appInfo.SteamUrl = $"steam://runsteamid/{appId}";
//if (appInfo.Name.StartsWith("Sid Meier"))
appInfo.Executable = GetExecutable(appInfo);
}
return appInfo;
}
static string _appInfoText = null;
static string GetExecutable(AppInfo appInfo)
{
if (_appInfoText == null)
{
var appInfoFile = Path.Combine(GetSteamPath(), "appcache", "appinfo.vdf");
var bytes = File.ReadAllBytes(appInfoFile);
_appInfoText = Encoding.UTF8.GetString(bytes);
}
var startIndex = 0;
int maxTries = 50;
var fullName = "";
do
{
var startOfDataArea = _appInfoText.IndexOf($"\x00\x01name\x00{appInfo.Name}\x00", startIndex);
if (startOfDataArea < 0 && maxTries == 50) startOfDataArea = _appInfoText.IndexOf($"\x00\x01gamedir\x00{appInfo.Name}\x00", startIndex); //Alternative1
if (startOfDataArea < 0 && maxTries == 50) startOfDataArea = _appInfoText.IndexOf($"\x00\x01name\x00{appInfo.Name}\x00", startIndex); //Alternative2
if (startOfDataArea > 0)
{
startIndex = startOfDataArea + 10;
int nextLaunch = -1;
do
{
var executable = _appInfoText.IndexOf($"\x00\x01executable\x00", startOfDataArea);
if (executable>-1 && nextLaunch == -1)
{
nextLaunch = _appInfoText.IndexOf($"\x00\x01launch\x00", executable);
}
if ((nextLaunch <= 0 || executable < nextLaunch) && executable > 0)
{
if (executable > 0)
{
executable += 10;
string filename = "";
while (_appInfoText[executable] != '\x00')
{
filename += _appInfoText[executable];
executable++;
}
if (filename.Contains("://"))
{
//EA or other external
return filename; //Need to use other means to grab the EXE here.
}
fullName = Path.Combine(appInfo.GameRoot, filename);
startOfDataArea = executable + 1;
startIndex = startOfDataArea + 10;
}
}
else
{
break;
}
}
while (!File.Exists(fullName) && maxTries-- > 0);
}
else
{
return null;
}
} while (!File.Exists(fullName) && maxTries-- > 0);
if (File.Exists(fullName)) return fullName;
return null;
}
static List<string> GetSteamLibs()
{
var steamPath = GetSteamPath();
var libraries = new List<string>() { steamPath };
var listFile = Path.Combine(steamPath, #"steamapps\libraryfolders.vdf");
var lines = File.ReadAllLines(listFile);
foreach (var line in lines)
{
var match = Regex.Match(line, #"""(?<path>\w:\\\\.*)""");
if (match.Success)
{
var path = match.Groups["path"].Value.Replace(#"\\", #"\");
if (Directory.Exists(path))
{
libraries.Add(path);
}
}
}
return libraries;
}
static string GetSteamPath()
{
return #"C:\Spill\Steam";
}
class AppInfo
{
public string Id { get; internal set; }
public string Name { get; internal set; }
public string SteamUrl { get; internal set; }
public string Manifest { get; internal set; }
public string GameRoot { get; internal set; }
public string Executable { get; internal set; }
public string InstallDir { get; internal set; }
public override string ToString()
{
return $"{Name} ({Id}) - {SteamUrl} - {Executable}";
}
}
}
}

The last value in Read.Line() StreamReader

Tell me please, how can I do so that would only give the last meaning of this search.
At the moment, about 15 MessageBox.Show is opened.
How to make it so that only the latter would show?
For the fifth hour I am suffering with different variations. Nothing happens.
TextReader tr = null;
try
{
File.Copy(SteamLogFilePath, tmpFile, true);
}
catch { }
try
{
tr = new StreamReader(tmpFile);
try
{
string line = null;
while (true)
{
line = tr.ReadLine();
if (line.Contains("RecvMsgClientLogOnResponse") && line.Contains("OK"))
{
tmpSplit1 = line.Split(')');
string SteamIdbrut = tmpSplit1[1];
tmpSplit1 = SteamIdbrut.Split(']');
string SteamIdnet = tmpSplit1[0].Replace(" : [", "");
long steam32 = Convert.ToInt64((GetFriendID(SteamIdnet)));
MessageBox.Show((FromSteam32ToSteam64(steam32)).ToString());
}
}
}
catch { }
}
catch { }
if (tr != null)
tr.Close();
You could use this instead:
string lastLine = File.ReadLines(tmpFile)
.Where(line => line.Contains("RecvMsgClientLogOnResponse") && line.Contains("OK"))
.LastOrDefault();
// rest of code to create the MessageBox
This code replaces all of your code from 2nd try to tr.Close();.

Checking if a user inputed string is in an array

So this is more than just checking if a user input string in an array because if the string is actually in the array and the bool returns true I want it to write some custom text.
{
static void Main(string[] args)
{
string[] name= {"Bob","Bob2","Bob3","Bob4"};
bool exists = name.Contains(string userName= Console.ReadLine());
if (exists == true)
Console.WriteLine("Hi " + userName);
Console.ReadLine();
}
}
I know I can't run the code like this but I'm looking for a similar way to run it but I'm not sure how to store user input and still have the bool check if the user inuputed string is in the string array.
you almost had it, just move the userName assignment up to its own line:
static void Main(string[] args)
{
string[] name = { "Bob", "Bob2", "Bob3", "Bob4" };
string userName = Console.ReadLine();
bool exists = name.Contains(userName);
if (exists == true)
Console.WriteLine("Hi " + userName);
Console.ReadLine();
}
here is the output:
Just declare your input variable outside of te Contains check:
static void Main(string[] args)
{
string[] name= {"Bob","Bob2","Bob3","Bob4"};
string userName = Console.ReadLine();
bool exists = name.Contains(userName);
if (exists == true)
Console.WriteLine("Hi " + userName);
Console.ReadLine();
}
I came up with this...
import java.util.Scanner;
public class inp {
public static void main (String args[]) {
String[] name = new String[] {
"Ben",
"Sam"
};
int max = name.length;
int current = 0;
boolean is = false;
System.out.println("What name tho?");
Scanner inp = new Scanner(System.in);
String nameInq = inp.next();
while(is == false && current<max) {
if(name[current].equals(nameInq)) {
is = true;
}else {
current++;
}
}
if(is) {
System.out.println("They are in the list");
}else {
System.out.println("nah");
}
}
}
Not quite as efficent but gets the job done.

How to handle continue statement in threading

Below code is used to move the data from local system to external hard drives. Client's requirement is to use threading for the same so as to speed up the copy of pages / minute.
I am facing one issue. I used continue statement under while loop which is not acceptable under thread. Can someone please suggest alternative of the same.
Thanks.
private void PromoteMain(TextWriter streamWriter)
{
string driveLetterString;
driveLetterString = GetExternalDrive();
if (!string.IsNullOrEmpty(driveLetterString))
{
DataSet dataSet;
DateTime startSnooze;
DataRow row;
string imageIdString;
string reelIdString;
string destImagePathString;
string[] strArrays;
int i;
string fileName;
string[] strArrays3;
string[] strArrays4;
bool flag;
string[] strArrays5;
bool flag1;
string[] strArrays6;
bool flag2;
string[] files;
TimeSpan timeSpan1;
IEnumerator iEnumerator1;
string[] stringArray1;
IDisposable iDisposable1;
dataSet = this.GetImagesFromDatabase();
if (((dataSet != null) && (dataSet.Tables.Count != 0)) && (dataSet.Tables[0].Rows.Count != 0))
{
iEnumerator1 = dataSet.Tables[0].Rows.GetEnumerator();
try
{
#region goto L_05A9
//goto L_05A9;
while (iEnumerator1.MoveNext())
{
driveLetterString = GetExternalDrive();
new Thread(() =>
{
if (!string.IsNullOrEmpty(driveLetterString))
{
row = ((DataRow)iEnumerator1.Current);
imageIdString = row["imageid"].ToString();
reelIdString = row["reelid"].ToString();
destImagePathString = row["destimagepath"].ToString();
if (!Directory.Exists(destImagePathString))
{
if (this.stringBuilderFail.Length > 0)
{
StringBuilder stringBuilder7 = this.stringBuilderFail.Append(",");
}
StringBuilder stringBuilder8 = this.stringBuilderFail.Append(imageIdString);
this._lblFailed.Text = Convert.ToString(((int)(Convert.ToInt32(this._lblFailed.Text) + 1)));
if (this.stringBuilderFail.Length > 7000)
{
this.UpdateImagesInDatabase(this.stringBuilderFail.ToString(), "5");
StringBuilder stringBuilder9 = this.stringBuilderFail.Remove(0, this.stringBuilderFail.Length);
}
this.RefreshFormView();
continue;
}
if (!Directory.Exists((driveLetterString + "newspaper\\" + reelIdString + "\\")))
{
DirectoryInfo directoryInfo1 = Directory.CreateDirectory((driveLetterString + "newspaper\\" + reelIdString + "\\"));
}
strArrays = new string[] { ".pdf", ".html", "_clean.html", "_lx.jpg" };
for (i = 0; (i < strArrays.Length); i++)
{
fileName = strArrays[i];
try
{
if (i != 2)
{
strArrays3 = new string[] { driveLetterString, "newspaper\\", reelIdString, "\\", imageIdString, fileName };
File.Copy((destImagePathString + imageIdString + fileName), string.Concat(strArrays3));
}
}
catch
{
}
}
strArrays4 = new string[] { driveLetterString, "newspaper\\", reelIdString, "\\", imageIdString, ".pdf" };
flag = File.Exists(string.Concat(strArrays4));
strArrays5 = new string[] { driveLetterString, "newspaper\\", reelIdString, "\\", imageIdString, "_lx.jpg" };
flag1 = File.Exists(string.Concat(strArrays5));
strArrays6 = new string[] { driveLetterString, "newspaper\\", reelIdString, "\\", imageIdString, ".html" };
flag2 = File.Exists(string.Concat(strArrays6));
if ((flag && flag1) && flag2)
{
streamWriter.WriteLine(imageIdString);
if (this.stringBuilderSuccess.Length > 0)
{
StringBuilder stringBuilder3 = this.stringBuilderSuccess.Append(",");
}
StringBuilder stringBuilder4 = this.stringBuilderSuccess.Append(imageIdString);
this._lblPromoted.Text = Convert.ToString(((int)(Convert.ToInt32(this._lblPromoted.Text) + 1)));
#region goto L_0453
L_0453();
continue;
#endregion
}
files = Directory.GetFiles((driveLetterString + "newspaper\\" + reelIdString + "\\"), (imageIdString + "*.*"));
stringArray1 = files;
foreach (string str6 in stringArray1)
{
try
{
File.Delete(str6);
}
catch
{
}
}
if (this.stringBuilderFail.Length > 0)
{
StringBuilder stringBuilder1 = this.stringBuilderFail.Append(",");
}
StringBuilder stringBuilder2 = this.stringBuilderFail.Append(imageIdString);
this._lblFailed.Text = Convert.ToString(((int)(Convert.ToInt32(this._lblFailed.Text) + 1)));
#region goto L_0453
L_0453();
continue;
#endregion
}
else
{
break;
};
}).Start();
}
#endregion
}
finally
{
iDisposable1 = (iEnumerator1 as IDisposable);
if (iDisposable1 != null)
{
iDisposable1.Dispose();
}
}
if (this.stringBuilderSuccess.Length > 0)
{
this.UpdateImagesInDatabase(this.stringBuilderSuccess.ToString(), "3");
StringBuilder stringBuilder10 = this.stringBuilderSuccess.Remove(0, this.stringBuilderSuccess.Length);
}
if (this.stringBuilderFail.Length > 0)
{
this.UpdateImagesInDatabase(this.stringBuilderFail.ToString(), "5");
StringBuilder stringBuilder11 = this.stringBuilderFail.Remove(0, this.stringBuilderFail.Length);
}
this.RefreshFormView();
#region goto L_0671
PromoteMain(streamWriter);
#endregion
}
else
{
startSnooze = DateTime.Now;
timeSpan1 = DateTime.Now.Subtract(startSnooze);
while (timeSpan1.TotalSeconds < 300D)
{
timeSpan1 = DateTime.Now.Subtract(startSnooze);
Thread.Sleep(125);
Application.DoEvents();
}
PromoteMain(streamWriter);
}
}
//else
//{
// MessageBox.Show("There is no space in selected drives");
// //there is no space in any external drive
//}
}
private void L_0453()
{
if (this.stringBuilderSuccess.Length > 7000)
{
this.UpdateImagesInDatabase(this.stringBuilderSuccess.ToString(), "3");
StringBuilder stringBuilder5 = this.stringBuilderSuccess.Remove(0, this.stringBuilderSuccess.Length);
}
if (this.stringBuilderFail.Length > 7000)
{
this.UpdateImagesInDatabase(this.stringBuilderFail.ToString(), "5");
StringBuilder stringBuilder6 = this.stringBuilderFail.Remove(0, this.stringBuilderFail.Length);
}
this.RefreshFormView();
}
Replace the continue statement with a return. This will complete the execution of the thread. Now I don't know how this continue statement ended up there but you can't actually continue since the operations are running in parallel. You should also extract this line
row = ((DataRow)iEnumerator1.Current);
or you risk the enumerator to change from another thread before it executes. You may also want to try Parallel.Foreach to reduce possible errors and get more effective execution. Even better would be to use async methods with async IO (as opposed to methods that use threads) and use Task.WaitAll to wait for them to complete.

Categories

Resources