Wednesday, August 24, 2016

How to compare Time only from the current date in C#

Following is the time comparison in 24 hour format

DateTime dt = DateTime.Parse(DateTime.Now.ToString ());

String strTime = dt.ToString("HH:mm");

if (strTime == System.Configuration.ConfigurationManager.AppSettings["ExecTime"].ToString())
{
// Matches
}

Or

if (strTime == “13:30”)
{
// Matches

}

Windows Search Service will not start, Error: "The Windows Search service on local computer started and then stopped. Some services stop automatically if they are not in use by other services or programs" – In C#, Windows service

Solution 1

Start - Run - then Type Services.msc and click enter button now you will get all the services in your computer after that select your service and right click on that and go to Properties
Then open Select Log On tab and then select Local System Account and click Ok
Restart your service

Solution 2

Check the framework version of the developed machine and the framework in the deployed machine

<startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>

Solution 3


Probability of this could be from the wrong configuration of project installer in the application, you will have to create a new project and copy the complete file except Project Installer. Configure the project installer once again 

Could not establish trust relationship for the ssl/tls secure channel with authority c# ASP.Net - Web service

In C#

System.Net.ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => { return true; };

In VB.Net

System.Net.ServicePointManager.ServerCertificateValidationCallback = 
Function(senderX, certificate, chain, sslPolicyErrors)
Return True
End Function


Add this line just before calling the Web service method, issue will be solved