Osama's Weblog

The place where you get updated!
  • rss
  • Home
  • Who am I?
  • RSS Feeds

How to schedule a windows service in .NET

Osama | March 29, 2010

I had a requirement of automate a task which could run after every 5 minutes. After spending some time on research, I decided to make a windows service and automate it. Automating a windows service is a bit tricky and it gave me a little hard time. Hence, I am sharing what did I code to complete the task.

When a new service created, OnStart & OnStop methods are initialized by default. You need to play with timers to get the task done.

Below is the code snippet which shows how to automate the windows service.

public partial class Service1

      {
        public Timer tm;  //initialize a new timer instance
        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            tm = new Timer();
            tm.AutoReset = true; //timer will reset and call the event handler function itself
            tm.Interval = 60000;  // time interval in milliseconds
            tm.Elapsed += new ElapsedEventHandler(timer_start);  //event which needs to be fired

            //once the timer reaches its maximum value
            tm.Start(); //start the timer

        }

protected void timer_start(object sender, ElapsedEventArgs e)

{

    //Perform your task here

}

protected override void OnStop()
        {
            tm.Start(); //start the timer again and it will call the event hander function again
        }

The above mentioned code snippet is self explanatory. I hope it helps whoever reads the post.

Feel free to ask questions

  • Share/Bookmark
Comments
No Comments »
Categories
.NET, General
Tags
.NET, scheduled, timer, windows service
Comments rss Comments rss
Trackback Trackback

Passing values to iframe from parent window through QueryString

Osama | March 14, 2010

I had a requirement of calling a web page which shows nothing but does some processing at the back end. But later on I decided to put a progress bar to make it attractive. I used JQuery UI to show the progress bar. The issue is JQuery is a javaScript library and it runs after the server side code is done processing. And my code was on the Page_Load method.

The solution which I found was to call the processing page within an iframe of the parent page. So that the progress bar will be shown on the parent page and will be loaded as soon as the page loads and the processing will be done within an iframe.

This is what I did to implement the above scenario:

///////////////Parent Page///////////////
<form id="form1" runat="server">
<iframe id="ifrm" frameborder="0"  runat="server" />
</form>

Code behind of the parent page:
protected void Page_Load(object sender, EventArgs e)
{
ifrm.Attributes["src"] = "Default2.aspx?id=" + Request["id"];
}

This will pass the id in the query string from the parent window the the iframe page. The iframe window will get the id from the query string and will do the desired processing.

Feel free to ask questions

  • Share/Bookmark
Comments
No Comments »
Categories
General
Tags
.NET, iframe, jquery, queryString
Comments rss Comments rss
Trackback Trackback

Apex InputField on Force.com site (contd..)

Osama | March 10, 2010

Few days ago I wrote a blog post in which I mentioned that I wasn’t able to access apex:input field on a force.com site. With the help of a my blog reader, I figured out what was the problem. Its pretty straight forward.

You cannot give extra permissions to standard objects on a force.com site. But  you can give Modify All Data and View All Data permissions to a custom object . That means you can use apex:inputField on a force.com site which is bound to a custom object field. Make sure about field level security.

Thanks to Jason.

  • Share/Bookmark
Comments
2 Comments »
Categories
APEX, VisualForce, salesforce
Tags
APEX, force.com, inputField
Comments rss Comments rss
Trackback Trackback

JQueryUI Datepicker in a Visualforce page

Osama | March 4, 2010

JQuery has always fascinates me. It makes the UI very attractive and user friendly. I had to implement a datepicker in a text field. I decided to use the JQuery UI datepicker. I am sharing the code that I did. Its easy to understand.

I made a static resource with the name slider and uploaded all the css and js files of JQuery UI that are available for download here .

1) Include the css files in your page

<link type="text/css" href="{!URLFOR($Resource.Slider, 'themes/ui-lightness/ui.all.css')}" rel="stylesheet" />
<script type="text/javascript" src="{!URLFOR($Resource.Slider, 'jquery-1.3.2.js')}"></script>
 <script type="text/javascript" src="{!URLFOR($Resource.Slider, 'ui/ui.core.js')}"></script>
 <script type="text/javascript" src="{!URLFOR($Resource.Slider, 'ui/ui.datepicker.js')}"></script>

2) Make a input text field and create the following JQuery function as below

 <input id="datepicker" type="textbox" />
<script type="text/javascript">
    $(function() {
        $("#datepicker").datepicker({ showOn: 'button', buttonImageOnly: true, buttonImage: '{!$Resource.calendar}' });
    });
    </script>;;

3)   $(“#datepicker”).datepicker({ showOn: ‘button’, buttonImageOnly: true, buttonImage: ‘{!$Resource.calendar}’ });
The datepicker pops up when you click on the image button that is created using the above statement. If  you want to pop it up by clicking the textbox only, replace the above statement with the below one:

  $(“#datepicker”).datepicker();

I hope it helps for you as it did for me. Feel free to ask questions

  • Share/Bookmark
Comments
11 Comments »
Categories
APEX, General, VisualForce, salesforce
Tags
APEX, datepicker, jquery, VisualForce
Comments rss Comments rss
Trackback Trackback

My status

Categories

  • .NET
  • APEX
  • consulting
  • General
  • Oracle CRM on Demand
  • salesforce
  • Uncategorized
  • VisualForce

MM Did You Know?

The Guinness Book of Records holds the record for being the book most often stolen from public libraries.
Plugin by mmilan

Its all about cloud

Salesforce

.NET .NET 4.0 beta actionFunction actionSupport administrator android APEX Apex variable API button certification cloud computing consulting controller custom DoDirectPayment force.com GET goggles google html images input inputField JavaScript jquery master-detail matcher Parallel Programming parameters pattern paypal query string REGEX regular expression salesforce search url variable Visual Force VisualForce Visual Studio vmware web service XML PARSING DOM SAX STAX

WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.

My Tweets

Error: Please make sure the Twitter account is public.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox