Long ago, I needed to capture 2 keys, shift and F5 keys during debugging for C# in VS 2010 and the following code: if(e.Shift && e.KeyCode == Keys.F5) However, no matter how fast or slow I pressed, the above statement will not be true. Since key events are received one at a time, if you pressed 10 keys at once they would be [...]
baran
Well, this snippet is from my old backup and let’s have a look for producer-consumer paradigm in action (in Java and .NET): Have a look how join works in Java: http://www.barantopal.com/technology/multithreading-and-join/ import java.util.Stack; import java.util.concurrent.atomic.AtomicInteger; /** * 1 producer and 3 consumers [...]
baran
Well, for garbage collection, I can say that it is a mechanism that objects are marked for destruction when no pointers are pointing to it (Num of references is 0). If you exit the scope of where the object was defined and you didn’t give any other object a pointer to that object then it is marked for destruction. GC is an [...]
baran
Say, I am having 2 tables, and in the 1st table, there is an ID and a age and in the 2nd table, there is a age, tallness, and if the first table’s age is equal to this tallness, the age in the second table should be searched in the first table’s age values and if not found, that row in the second table should be deleted. Here [...]
baran
Say we have the following string source and want to replace a substring. string source = "I am researching searchlights"; Regex.Replace(source, @"(?\w*)search(?\w*)", @"${wc1}pair${wc2}"); source.Replace("search", "pair"); Both of them will return: I am repairing pairlights If you are going to use Regex technique for a long text (longer [...]
baran
This post will grow later on but let’s start from the definition of XML Schema Definition. The xsd is a XML Schema Definition file, which is used to validate XML or generate DOM classes (through the Xsd.exe Tool, for example). The Xsd.exe /dataset option generates a class derived from DataSet that corresponds to the specified [...]
baran
This is a handy one that I found while googling. Credits to the owner of the script. These are the steps you need to follow: 1) Stop SQL Server instance 2) Start SQL Server instance in Single user mode 3) Run the Restore command 4) Stop SQL Server instance 5) Start SQL Server instance in Multi user mode Net stop MSSQLSERVER Net start [...]
baran
This is a script I use every now and then for renumeration of attachments. It was working fine even in Outlook 2007. Note that if the attachment name is the same (and typically it is if you scan a document, then it handles these gently and renames the files incrementally). Open up your Outlook: Be sure you put all the files into a folder [...]
baran
Here is another gem that I found in my backups 🙂 Below program will create 12 thread that try to write data into C:\MyFile.txt in a syncronized fashion in C#. using System; using System.Collections.Generic; using System.Threading; using System.Text; namespace ThreadDemo { class Program { static void Main(string[] args) { MyClass myClass [...]
baran
Here is another gem in C#. I need to test this though 🙂 //Client side using System; using System.Collections.Generic; using System.Text; using System.Net; using System.Net.Sockets; using System.IO; namespace ClientServer { //FILE TRANSFER USING C#.NET SOCKET - CLIENT class Program { static void Main(string[] args) { try { [...]
baran