How to add memcached to system start-up in Windows Server 2008


I have spent a whole day or two only in trying to make memcached start-up automatically on system restart in Windows 2008 Server system. I was getting this error “memcached.exe exits with Failed to ignore SIGHUP” when I tried to use the -d switch. In the end, it turned out to be pretty simple but trying to do it with Windows NT Resource Kit, PowerShell’s New-Service command, srvany.exe or the likes did NOT work at all for me. What worked for me was this:

  1. You go to Run > “RegEdit” hit enter.
  2. Then you find the key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
  3. Add a string value to it, name it whatever you want and put the full path to the memcached.exe file into the value of it.
Add memcached.exe to startup in Registry
Add memcached.exe to startup in Registry in Windows 2008 Server

Now you should be able to see the memcached startup when you reboot the system.

PS: In case you have a dependent service on memcached, change its start-up type to Automatic(delayed)

Advertisements

How to manipulate a Windows Forms control from another thread and get return value via Invoke() method


I was working on a Windows Forms project and I had this requirement to basically do some manipulation on a TreeListView on the parent form (MainForm in this case) for which we already had a developed a method and also to get the return value back from it. To make life even easier, we needed to do this from a BackGroundWorker thread in this case. Now, the problem with Windows Forms controls is that they can’t be manipulated apart from the main thread, so I had to look for a work around of some sort. So here’s a little modified snippet of the code for your understanding:-

if (m.treeListView.InvokeRequired)
{
ra= (ReportData?)m.treeListView.Invoke(new Func<ReportData?>(
() => m.CreateDataforReport(“Rpt type”, false)));
//m is the main form’s reference!

}

So what I’ve done is that I passed the main form’s reference to the child form in the constructor and made the TreeListView and the CreateDataforReport public. Notice that I called CreateDataforReport method inside the Func<ReportData?> and not directly. This is what enables you to get the appropriate return value, be it string, integer or any complex type like I have it here.

Unknown server tag ‘asp:ScriptManager’ After having AjaxControlToolkit.dll referenced


Yesterday I was working on a project which had the AJAX Extensions in use. It’s primarily a .NET 2.0 application and I had .NET Framework 3.5 SP 1 installed on my system. It was working normally and all of a sudden I got this error that: Unknown server tag ‘asp:ScriptManager’

It was strange because every thing was working and I had the reference to the AjaxControlToolkit.dll.

I found out that by adding the section below to the <system.web> node in the web.config solves the problem:-
<pages>

<controls>

<add tagPrefix=”asp” namespace=”System.Web.UI” assembly=”System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ />

</controls>

</pages>

Properties in .NET


Property in C#:

Property ? it is a special method that can return a current object?s state or set it. Simple syntax of properties can see in the following example:

public int Old 
{
   get {return m_old;}
   set {m_old = value;}
 } 
public string Name 
{
   get {return m_name;} 
}

Here are two types of properties. A first one can set or get field of class named m_old, and the second is read only. That?s mean it can only get current object?s state.

The significance of these properties is its usability. These properties need not be called with any function names like objectname.get or objectname.set etc., But they can be directly assigned the values or retrieve the values.

The VB .NET Syntax of declaring a property is as follows:-

Public Property X() As Integer
Get
     Return
x
End
Get
Set(ByVal Value As Integer
)
     x = value
End
Set
End Property