Executable directory where application is running from?

This is the first post on google so I thought I’d post different ways that are available and how they compare. Unfortunately I can’t figure out how to create a table here, so it’s an image. The code for each is below the image using fully qualified names. My.Application.Info.DirectoryPath Environment.CurrentDirectory System.Windows.Forms.Application.StartupPath AppDomain.CurrentDomain.BaseDirectory System.Reflection.Assembly.GetExecutingAssembly.Location System.Reflection.Assembly.GetExecutingAssembly.CodeBase New … Read more

Listen to key press when the program is in the background

You can use P/Invocation to be able to use WinAPI’s GetAsyncKeyState() function, then check that in a timer. <DllImport(“user32.dll”)> _ Public Shared Function GetAsyncKeyState(ByVal vKey As System.Windows.Forms.Keys) As Short End Function Const KeyDownBit As Integer = &H8000 Private Sub Timer1_Tick(sender As Object, e As System.EventArgs) Handles Timer1.Tick If (GetAsyncKeyState(Keys.LWin) And KeyDownBit) = KeyDownBit AndAlso (GetAsyncKeyState(Keys.O) … Read more

Help with Linq and Generics. Using GetValue inside a Query

You need to convert the code to an expression tree. using System; using System.Linq; using System.Linq.Expressions; using System.Reflection; namespace WindowsFormsApplication1 { static class Program { [STAThread] static void Main() { using (var context = new NorthwindEntities()) { IQueryable<Customer> query = context.Customers; query = Simplified<Customer>(query, “CustomerID”, “ALFKI”); var list = query.ToList(); } } static IQueryable<T> Simplified<T>(IQueryable<T> … Read more

How to call the Magento API from VB.NET

Function getHTTPStream() As String Dim myh As HttpWebRequest = _ HttpWebRequest.Create(“http://yourmagentoweb/soap/api/?wsdl”) myh.Timeout = 30000 myh.UserAgent = “Test” Dim myR As HttpWebResponse = myh.GetResponse() Dim myEnc As Encoding = Encoding.GetEncoding(1252) Dim mySr As StreamReader = New StreamReader(myR.GetResponseStream(), myEnc) Return mySr.ReadToEnd() End Function That code needs tweaking obviously- i have not got time to prettify this stuff … Read more

How do I specify the equivalent of volatile in VB.net?

There’s no equivalent of C#’s volatile keyword in VB.NET. Instead what’s often recommended is the use of MemoryBarrier. Helper methods could also be written: Function VolatileRead(Of T)(ByRef Address As T) As T VolatileRead = Address Threading.Thread.MemoryBarrier() End Function Sub VolatileWrite(Of T)(ByRef Address As T, ByVal Value As T) Threading.Thread.MemoryBarrier() Address = Value End Sub Also … Read more

VB Detect Idle time

This is done easiest by implementing the IMessageFilter interface in your main form. It lets you sniff at input messages before they are dispatched. Restart a timer when you see the user operating the mouse or keyboard. Drop a timer on the main form and set the Interval property to the timeout. Start with 2000 … Read more