Skip to main content

How to create task scheduler in C#

Today I will elucidate about undertaking scheduler in c# and how to booked on particular time in window.Today i will make an errand scheduler utilizing c# reassure application to call or expend rest web programming interface with intermediary to get information from sharepoint .This illustration use to devour web programming interface to call sharepoint to download report on neighborhood application catalog.

How to make Task scheduler in c# application?

Step 1:- Create a reassure application in c#

Step 2:- You have to include Microsoft.SharePoint.Client library from chunk bundle in you application.

utilizing System;

utilizing System.IO;

utilizing System.Net;

utilizing System.Net.Http;

utilizing System.Net.Http.Headers;

utilizing System.Threading.Tasks;

utilizing System.Configuration;

utilizing System.Security;

utilizing Microsoft.SharePoint.Client;

namespace InsightTaskSchedular{

class Program {

static void Main()

{

attempt {

/to validate from sharepoint server.

string UserName = ConfigurationSettings.AppSettings["UserName"].ToString();

string Password = ConfigurationSettings.AppSettings["Password"].ToString();

string userName = UserName;

string secret key = Password;

string baseurl = "***********Sharepoint URL";

Uri = new Uri(baseurl);

var securePassword = new SecureString();

foreach (var c in secret key) { securePassword.AppendChar(c); }

var certifications = new SharePointOnlineCredentials(userName, securePassword);

/get authCookie from sharepoint utilizing username and secret word.

var authCookie = credentials.GetAuthenticationCookie(uri);

string fedAuthString = authCookie.TrimStart("SPOIDCRL=".ToCharArray());

in the case of (fedAuthString != invalid)

{

/call capacity to devour web programming interface utilizing fedAuthString as token for programming interface.

RunAsync(fedAuthString).Wait();

/Console.WriteLine(fedAuthString);

/Console.Read();

}

else {

Console.WriteLine("Invalid User!!");

}

}

get (TaskCanceledException ex)

{

Console.WriteLine(ex);

Console.Read();

}

}

static async Task RunAsync(string fedAuthString)

{

attempt {

utilizing (HttpClient _client = new HttpClient())

{

/By default httpclient timeout=100 second.

_client.Timeout = TimeSpan.FromHours(1);

string BaseApiUrl = ConfigurationSettings.AppSettings["BaseApiUrl"].ToString();

_client.BaseAddress = new Uri(BaseApiUrl);

_client.DefaultRequestHeaders.Accept.Clear();

_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

_client.DefaultRequestHeaders.Add("SPOIDCRL", fedAuthString);

HttpResponseMessage reaction = anticipate _client.GetAsync("/programming interface/Insight/DownloadDocument");

on the off chance that (response.IsSuccessStatusCode)

{

Console.WriteLine("Sucess!!");

}

}

}

get (TaskCanceledException ex)

{

Console.WriteLine(ex);

Console.Read();

}

}

}

}

Step 3:- Set intermediary and userName and watchword in app.config document.

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<system.net>

<defaultProxy>

<proxy proxyaddress="proxy IP:port" usesystemdefault="true" bypassonlocal="true"/>

</defaultProxy>

</system.net>

<appSettings>

<add key="UserName" value="***********"/>

<add key="Password" value="************"/>

<add key="BaseApiUrl" value="***********:Port"/>

</appSettings>

<startup>

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

</startup>

</configuration>

Step 3:- You can change this code concurring your requirment and run support application.

from that point check container envelope your application index to execute .exe on anyplace.

How to utilize errand scheduler in window working framework?

Step 1:- Open Task scheduler utilizing these means.

Open laud prompt=> sort "Taskschd.msc" from there on open window like this

Principle window

Step 2:- Create new errand in undertaking scheduler utilizing these progression given underneath.

Assignment Scheduler Library=>right click=>Create Task from that point open window like this and set errand Name and depiction and other design concurring your requirment .

General window

Step 3:- Now you will make trigger to plan your assignment agreeing your requirment like this.

trigger window

Step 4:- Now you will make activities for .exe. tap on Browse and set way of exe document .

e.g. ...\InsightTaskSchedular\bin\Debug\InsightTaskSchedular.exe

Activity window

Step 5:- Now you can set other setting agreeing your requirment and also other.

also, tap on "OK".Thereafter you can check your undertaking in errand board

Your errand will keep running at planned time precisely.

Comments

Popular posts from this blog

EncryptByPassPhrase and DecryptByPassPhrase in sql server

This Article explains you how to Encrypt and Decrypt a text in sql server EncryptByPassPhrase: Syntax:  ENCRYPTBYPASSPHRASE ('PASSPHRASE', ‘text’) creating table Login table create table login(id int identity(1,1),username varchar(10),password varchar(100))  insert into login (username,password)values('Ramprasad',EncryptByPassPhrase('12','AAA'))  insert into login (username,password)values('venkat',EncryptByPassPhrase('12','BBB'))  insert into login (username,password)values('hemanth',EncryptByPassPhrase('12','CCC')) select * from login id username         password 1 Ramprasad         2 venkat                 3 hemanth                 now we are not able to see the passwords .To visible the Passwords we need to Decrypt the passwords DecryptByPassPhrase :      Decrypt PassPhrase takes two parameters  one is  ' PASSPHRASE ' and 

Insert multiple rows at a time in sql server

Insert multiple rows at a time in sql server synatax: insert into @extable(id,firstname,lastname) values(val1,val2,val3), (val4,val5,val6) example declare   @ extable  table ( id   int , firstname   varchar ( 50 ), lastname   varchar ( 50) insert   into   @ extable ( id , firstname , lastname ) values (1 , 'krishna' , 'kumar' ), (2 , 'kalyan' , 'goud' ), (3 , 'praveen' , 'kumar' ) select * from   @extable