|
Use Background worker report progress to trigger different conditions on the main thread.
*** Ya Ya I know..background workers But I didn't architect the project
Private Sub Go(myList as list(of String))
bgw1.RunWorkerAsync(me,myList)
End Sub
Private Sub bgw1_DoWork(sender As Object, e As DoWorkEventArgs) Handles bgw1.DoWork
Dim myList As List(Of String) = e.Argument
Dim listCount As Integer = myList.Count
For i As Integer = 0 To listCount
Dim resultInteger = DoWork(myList(i))
bgw1.ReportProgress(resultInteger,myList(i))
Next
End Sub
Private Sub bgw1_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles bgw1.ProgressChanged
Dim p As Integer = e.ProgressPercentage
Dim s As String = CStr(e.UserState)
Select Case P
Case 1
lbl1.Text = s
Case 2
lbl2.Text = s
Case Else
lbl1.Text = "Invalid Result for " & s
lbl2.Text = "Invalid Result for " & s
End Select
End Sub
modified 10-Jan-23 11:06am.
|
|
|
|
|
Always wrap any third party or sufficiently complicated built-in API with your own API.
The original API or third party will change or become deprecated in about 10 years.
A good rule for code that you expect to last 20 years or more.
If you expect a five year life span then it might not be worth it.
|
|
|
|
|
To toggle a flag variable that has values of 0 and 1:
Flag = 1 - Flag
FormerBIOSGuy
|
|
|
|
|
This has been happening for me for quite a while on Windows 10...I never inquired about it, and just now, Google searches returned nothing relevant (or my keywords aren't good enough).
Every once in a while...I'll try to RDP (by launching mstsc.exe) into a system I have on my LAN...I provide the machine name, hit Connect, then the standard (Windows 10) credentials window does NOT come up. But it's there - if I move the mouse over the RDP icon on the taskbar, there's a Remote Desktop Connection entry in its popup menu, and if I just move the mouse over it, the credentials window comes up...only, the layout is completely messed up:
I have a 4K monitor, and the window is resized to such extremely large proportions, I only see the Remember Me checkbox in the top-left corner, then on the bottom of the screen, the OK button has a normal height, but is so wide it occupies half the screen (at 4K!); the Cancel button looks the same; normal height, but the width takes up the other half of the screen. The password textbox is "out of bounds", and I have to have the mouse hover over/leave the icon on the taskbar repeatedly and/or try to cancel (Esc)/hit Connect again, so the credentials window might eventually resize itself correctly on its own.
Has anyone else seen this? It's been going on for years, and whether it'll work correctly or not on the first attempt is anyone's guess.
|
|
|
|
|
This rather plain vanilla operation in terms of a user view point is surprising complicated in Windows.
This is used to be easy to do using grep or some version of it.
Hey, Microsoft how about this command
search for "text" in all text files "on my disk"
and I mean that simple.
No ??..xxgreppx */*/.*(*dmmd
Grrrr.
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
Try Google - maybe they are wrong, but it is a start.
|
|
|
|
|
Google used have a search engine one could use search you own system (can't recall it's exact name google_something). They don't have it anymore.
It was great.
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
I believe you are talking about this: Google Desktop - Wikipedia. I think it was known for sending lots of data back to Google, if my memory serves, but everyone liked it. It also became redundant when Windows added about the same thing with its file search capabilities where it databased everything (which is what Google also did I believe).
I'll also add my two cents for Agent Ransack, which I use occasionally.
|
|
|
|
|
Yeah, it was Desktop Google. Trying Ransack. Works reasonably well.
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
|
I have used find command, but does not recursive search, but I learned that FINDSTR command does. I'll try it.
wish Windows had a more general search engine like a google equivalent built-in.
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
Basically the idea from unix (or before) was that command line commands were supposed to be stacked.
Apparently powershell took that to heart. If you search for the following you can do it with find but it requires more than one command.
powershell find recursive
For myself the editor I use has a search feature which even include regex if I want. So I just use that.
|
|
|
|
|
If you don't need to it in a batch file, have a look at Agent Ransack from Mythicsoft.
// TODO: Insert something here Top ten reasons why I'm lazy
1.
|
|
|
|
|
|
Agent Ransack
I have not tried this, but, check out: [^]
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
modified 8-Jan-23 9:24am.
|
|
|
|
|
This has been mentioned several times. I will give it try. Thanx
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
Roll your own. Make it do exactly what you want. You can't expect someone else to have already done it for you.
|
|
|
|
|
Maybe I'm missing some nuance in your post, but have you tried finest?
|
|
|
|
|
I use Notepad++ for searching in a specific file - so I use Notepad++ for searching in all files.
It lets me select between case sensitive and insensitive search.
It lets me search for whole words only.
It lets me search for either plain strings, strings with control characters escaped by backslashes, or a regular expession.
It lets me filter files by name and/or extension, with a list of alternatives (such as "*.txt;*.log;*.cs")
It lets me select files in a single directory or also in subdirectories.
It lets me replace the found string with another text in all matching files.
It lets me navigate the directory tree graphically for selecting the directory (tree) to search.
It handles files in various encodings, including UTF-8 and different line ending conventions.
It lets me fetch two (or more) files with hits, and compare them (with plugin, but a standard one that should always be installed).
The hit list is very well organized: It shows a single line for each hit; you can open that file on that line by clicking it. You can temporarily hide all hits in one (or all) files. You can delete files of no interest from the hit list, while continuing to inspect the remaining ones.
It is quite fast.
But most of all: Using the same tool, with the same dialog fields, for searching a directory tree as the one you use for searching in the one text file you are editing means that there is no new tool to learn, no new command syntax or specification format. It is familiar and friendly.
This of course is if np++ already is your standard text file editor. If it is not, my question is "Why not?"
|
|
|
|
|
Notepad++ also handles multi byte, BOM, BOMless, etc whereas cmd’s FIND /s and FINDSTR /s only work with single byte characters.
|
|
|
|
|
Wow, Did not know Notepad++ did this. Thanx, Trønderen and Englebart. I'll try it
"A little time, a little trouble, your better day"
Badfinger
modified 8-Jan-23 19:56pm.
|
|
|
|
|
If you have Linqpad -- LINQPad - The .NET Programmer's Playground[^] -- (and what self-respecting C# dev doesn't ) then I got your back on this:
Here's a great little findInFiles script I wrote a few years ago when i was frustrated because I couldn't search inside of source code (*.cs) to find specific text items I needed.
Keep in mind I wrote this very quickly bec I was needing to search in files for specific text.
It ignores case and finds all matches ( you can add a parameter to handle this).
it will prompt you for a few items:
1. Directory you want to search (searches all subdirs)
2. text you want to search for.
3. file pattern you want to search against *.*, *.cs, *.txt, etc.
that's it. It'll go through them all and give you some results.
Yes, it's just bruteforce but it works and it's relatively fast and you'll see updated results as it finds the text.
void Main()
{
Console.WriteLine ("Enter the path you want to search.");
string searchPath = Console.ReadLine();
Console.WriteLine(string.Format("Searching : {0}", searchPath));
DirectoryInfo DirInfo = new DirectoryInfo(searchPath);
Console.Write("Search Term: ");
string searchTerm = Console.ReadLine().ToUpper();
Console.WriteLine(searchTerm);
Console.WriteLine("Enter the file pattern you want search against.");
string filePattern = Console.ReadLine();
try
{
var files = DirInfo.EnumerateFiles(filePattern,SearchOption.AllDirectories);
foreach (var f in files)
{
string [] allLines = File.ReadAllLines(f.FullName);
int lineCount = 1;
bool foundInFile = false;
foreach (string line in allLines)
{
if (line.ToUpper().Contains(searchTerm))
{
if (!foundInFile)
{
Console.WriteLine("searching {0}", f.FullName.ToUpper());
foundInFile=true;
}
Console.WriteLine(string.Format("FOUND : {0} {1}",lineCount, line));
}
lineCount++;
}
if (foundInFile)
{
Console.WriteLine("#############################");
Console.WriteLine();
}
}
}
finally
{
}
}
modified 8-Jan-23 12:41pm.
|
|
|
|
|
Wow ! thanks ...
May I suggest you publish this as a Tip/Trick, or flesh iit out a little bit and publish as article.
I can "see" adding an Enum that would filter on either lower or upper case matches, or both.
cheers, Bill
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
modified 9-Jan-23 2:29am.
|
|
|
|
|
That's a great idea and I will try to get around to it. Thanks
|
|
|
|
|
Be careful - if your account doesn't have permission to read any of the folders in the search path, the script will fail at the first one. In .NET Framework, there's no way to make a SearchOption.AllDirectories search skip folders you don't have access to.
If you're using .NET Core 2.1 or later (including .NET 5/6/7/...), you can use the EnumerationOptions[^] class with the IgnoreInacessible property set to true to resolve this:
EnumerationOptions options = new()
{
RecurseSubdirectories = true,
IgnoreInaccessible = true,
};
var files = DirInfo.EnumerateFiles(filePattern, options);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|