2012/11/19

How to work Background Worker

 BackgroundLoading.cs
----------------------------------------------------------
public class BackgroundLoading
    {
        public delegate void RunFunction();

        public BackgroundWorker Bw;
        public RunFunction thisFunction;
        FrmLoding newLoading;

        public BackgroundLoading(RunFunction newFunction)
        {
            try
            {
                System.Threading.ThreadStart ts = new System.Threading.ThreadStart(ExpansiveMethod);
                System.Threading.Thread t = new System.Threading.Thread(ts);
                t.Start();

                thisFunction = newFunction;
                Bw = new BackgroundWorker();
                Bw.DoWork += new DoWorkEventHandler(Bw_DoWork);
                Bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Bw_RunWorkerCompleted);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        public void Start()
        {
            try
            {
              
                Bw.RunWorkerAsync();               
                newLoading = new FrmLoding();
                newLoading.ShowDialog();
              
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        protected void ExpansiveMethod()
        {
            //Very expansive call will go here...
            //after the job is finished call method to update ui
            MethodInvoker updaterMI = new MethodInvoker(UpdateChange);
            this.UpdateChange();
        }
        protected void UpdateChange()
        {
            //again back to main ui thread
        }
        void Bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            try
            {
                newLoading.Close();
                ExpansiveMethod();

            }
            catch (Exception ex)
            {
                throw;
            }
        }


        void Bw_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                if (thisFunction != null)
                {
                    thisFunction();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
    }

--------------------------------------WPF Control............................LoadingAnimation.xmal
<UserControl x:Class="VISION.LoadingAnimation"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:VISION"
    Height="Auto" Width="Auto">
    <UserControl.Resources>
        <Storyboard x:Key="ProgressAnimation" RepeatBehavior="Forever">
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="block" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00" Value="Black"/>
                <SplineColorKeyFrame KeyTime="00:00:00.2290000" Value="#EF000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.4590000" Value="#E2000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.6880000" Value="#D3000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.9180000" Value="#C6000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.1470000" Value="#B7000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.3760000" Value="#AA000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.6060000" Value="#9B000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.8350000" Value="#8E000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.0650000" Value="#7F000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.2940000" Value="#72000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.5240000" Value="#63000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.7530000" Value="#56000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.9820000" Value="#3D000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.2120000" Value="#26000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.4410000" Value="#19000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.6710000" Value="#0C000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.9000000" Value="#00000000"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="block17" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00" Value="#EF000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.2290000" Value="#E2000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.4590000" Value="#D3000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.6880000" Value="#C6000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.9180000" Value="#B7000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.1470000" Value="#AA000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.3760000" Value="#9B000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.6060000" Value="#8E000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.8350000" Value="#7F000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.0650000" Value="#72000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.2940000" Value="#63000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.5240000" Value="#56000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.7530000" Value="#3D000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.9820000" Value="#26000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.2120000" Value="#19000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.4410000" Value="#0C000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.6710000" Value="#00000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.9000000" Value="Black"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="block16" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00" Value="#E2000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.2290000" Value="#D3000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.4590000" Value="#C6000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.6880000" Value="#B7000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.9180000" Value="#AA000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.1470000" Value="#9B000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.3760000" Value="#8E000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.6060000" Value="#7F000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.8350000" Value="#72000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.0650000" Value="#63000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.2940000" Value="#56000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.5240000" Value="#3D000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.7530000" Value="#26000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.9820000" Value="#19000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.2120000" Value="#0C000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.4410000" Value="#00000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.6710000" Value="Black"/>
                <SplineColorKeyFrame KeyTime="00:00:03.9000000" Value="#EF000000"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="block15" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00" Value="#D3000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.2290000" Value="#C6000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.4590000" Value="#B7000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.6880000" Value="#AA000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.9180000" Value="#9B000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.1470000" Value="#8E000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.3760000" Value="#7F000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.6060000" Value="#72000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.8350000" Value="#63000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.0650000" Value="#56000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.2940000" Value="#3D000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.5240000" Value="#26000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.7530000" Value="#19000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.9820000" Value="#0C000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.2120000" Value="#00000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.4410000" Value="Black"/>
                <SplineColorKeyFrame KeyTime="00:00:03.6710000" Value="#EF000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.9000000" Value="#E2000000"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="block14" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00" Value="#C6000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.2290000" Value="#B7000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.4590000" Value="#AA000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.6880000" Value="#9B000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.9180000" Value="#8E000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.1470000" Value="#7F000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.3760000" Value="#72000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.6060000" Value="#63000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.8350000" Value="#56000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.0650000" Value="#3D000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.2940000" Value="#26000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.5240000" Value="#19000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.7530000" Value="#0C000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.9820000" Value="#00000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.2120000" Value="Black"/>
                <SplineColorKeyFrame KeyTime="00:00:03.4410000" Value="#EF000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.6710000" Value="#E2000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.9000000" Value="#D3000000"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="block13" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00" Value="#B7000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.2290000" Value="#AA000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.4590000" Value="#9B000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.6880000" Value="#8E000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.9180000" Value="#7F000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.1470000" Value="#72000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.3760000" Value="#63000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.6060000" Value="#56000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.8350000" Value="#3D000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.0650000" Value="#26000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.2940000" Value="#19000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.5240000" Value="#0C000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.7530000" Value="#00000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.9820000" Value="Black"/>
                <SplineColorKeyFrame KeyTime="00:00:03.2120000" Value="#EF000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.4410000" Value="#E2000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.6710000" Value="#D3000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.9000000" Value="#C6000000"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="block12" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00" Value="#AA000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.2290000" Value="#9B000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.4590000" Value="#8E000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.6880000" Value="#7F000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.9180000" Value="#72000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.1470000" Value="#63000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.3760000" Value="#56000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.6060000" Value="#3D000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.8350000" Value="#26000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.0650000" Value="#19000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.2940000" Value="#0C000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.5240000" Value="#00000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.7530000" Value="Black"/>
                <SplineColorKeyFrame KeyTime="00:00:02.9820000" Value="#EF000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.2120000" Value="#E2000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.4410000" Value="#D3000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.6710000" Value="#C6000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.9000000" Value="#B7000000"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="block11" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00" Value="#9B000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.2290000" Value="#8E000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.4590000" Value="#7F000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.6880000" Value="#72000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.9180000" Value="#63000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.1470000" Value="#56000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.3760000" Value="#3D000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.6060000" Value="#26000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.8350000" Value="#19000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.0650000" Value="#0C000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.2940000" Value="#00000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.5240000" Value="Black"/>
                <SplineColorKeyFrame KeyTime="00:00:02.7530000" Value="#EF000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.9820000" Value="#E2000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.2120000" Value="#D3000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.4410000" Value="#C6000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.6710000" Value="#B7000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.9000000" Value="#AA000000"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="block10" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00" Value="#8E000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.2290000" Value="#7F000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.4590000" Value="#72000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.6880000" Value="#63000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.9180000" Value="#56000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.1470000" Value="#3D000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.3760000" Value="#23000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.6060000" Value="#19000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.8350000" Value="#0C000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.0650000" Value="#00000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.2940000" Value="Black"/>
                <SplineColorKeyFrame KeyTime="00:00:02.5240000" Value="#EF000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.7530000" Value="#E2000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.9820000" Value="#D3000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.2120000" Value="#C6000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.4410000" Value="#B7000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.6710000" Value="#AA000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.9000000" Value="#9B000000"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="block9" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00" Value="#7F000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.2290000" Value="#72000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.4590000" Value="#63000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.6880000" Value="#56000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.9180000" Value="#3D000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.1470000" Value="#26000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.3760000" Value="#19000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.6060000" Value="#0C000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.8350000" Value="#00000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.0650000" Value="Black"/>
                <SplineColorKeyFrame KeyTime="00:00:02.2940000" Value="#EF000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.5240000" Value="#E2000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.7530000" Value="#D3000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.9820000" Value="#C6000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.2120000" Value="#B7000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.4410000" Value="#AA000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.6710000" Value="#9B000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.9000000" Value="#91000000"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="block8" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00" Value="#72000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.2290000" Value="#63000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.4590000" Value="#56000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.6880000" Value="#3D000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.9180000" Value="#26000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.1470000" Value="#19000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.3760000" Value="#0C000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.6060000" Value="#00000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.8350000" Value="Black"/>
                <SplineColorKeyFrame KeyTime="00:00:02.0650000" Value="#EF000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.2940000" Value="#E2000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.5240000" Value="#D3000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.7530000" Value="#C6000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.9820000" Value="#B7000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.2120000" Value="#AA000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.4410000" Value="#9B000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.6710000" Value="#91000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.9000000" Value="#7F000000"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="block7" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00" Value="#63000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.2290000" Value="#56000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.4590000" Value="#3D000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.6880000" Value="#26000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.9180000" Value="#19000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.1470000" Value="#0C000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.3760000" Value="#00000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.6060000" Value="Black"/>
                <SplineColorKeyFrame KeyTime="00:00:01.8350000" Value="#EF000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.0650000" Value="#E2000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.2940000" Value="#D3000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.5240000" Value="#C6000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.7530000" Value="#B7000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.9820000" Value="#AA000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.2120000" Value="#9B000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.4410000" Value="#91000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.6710000" Value="#7F000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.9000000" Value="#72000000"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="block6" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00" Value="#56000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.2290000" Value="#3D000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.4590000" Value="#26000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.6880000" Value="#19000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.9180000" Value="#0C000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.1470000" Value="#00000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.3760000" Value="Black"/>
                <SplineColorKeyFrame KeyTime="00:00:01.6060000" Value="#EF000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.8350000" Value="#E2000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.0650000" Value="#D3000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.2940000" Value="#C6000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.5240000" Value="#B7000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.7530000" Value="#AA000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.9820000" Value="#9B000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.2120000" Value="#91000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.4410000" Value="#7F000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.6710000" Value="#72000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.9000000" Value="#63000000"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="block5" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00" Value="#3D000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.2290000" Value="#26000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.4590000" Value="#19000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.6880000" Value="#0C000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.9180000" Value="#00000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.1470000" Value="Black"/>
                <SplineColorKeyFrame KeyTime="00:00:01.3760000" Value="#EF000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.6060000" Value="#E2000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.8350000" Value="#D3000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.0650000" Value="#C6000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.2940000" Value="#B7000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.5240000" Value="#AA000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.7530000" Value="#9B000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.9820000" Value="#91000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.2120000" Value="#7F000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.4410000" Value="#72000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.6710000" Value="#63000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.9000000" Value="#56000000"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="block4" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00" Value="#26000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.2290000" Value="#19000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.4590000" Value="#0C000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.6880000" Value="#00000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.9180000" Value="Black"/>
                <SplineColorKeyFrame KeyTime="00:00:01.1470000" Value="#EF000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.3760000" Value="#E2000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.6060000" Value="#D3000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.8350000" Value="#C6000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.0650000" Value="#B7000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.2940000" Value="#AA000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.5240000" Value="#9B000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.7530000" Value="#91000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.9820000" Value="#7F000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.2120000" Value="#72000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.4410000" Value="#63000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.6710000" Value="#56000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.9000000" Value="#3D000000"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="block3" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00" Value="#19000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.2290000" Value="#0C000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.4590000" Value="#00000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.6880000" Value="Black"/>
                <SplineColorKeyFrame KeyTime="00:00:00.9180000" Value="#EF000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.1470000" Value="#E2000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.3760000" Value="#D3000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.6060000" Value="#C6000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.8350000" Value="#B7000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.0650000" Value="#AA000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.2940000" Value="#9B000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.5240000" Value="#91000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.7530000" Value="#7F000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.9820000" Value="#72000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.2120000" Value="#63000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.4410000" Value="#56000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.6710000" Value="#3D000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.9000000" Value="#26000000"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="block2" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00" Value="#0C000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.2290000" Value="#00000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.4590000" Value="Black"/>
                <SplineColorKeyFrame KeyTime="00:00:00.6880000" Value="#EF000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.9180000" Value="#E2000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.1470000" Value="#D3000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.3760000" Value="#C6000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.6060000" Value="#B7000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.8350000" Value="#AA000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.0650000" Value="#9B000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.2940000" Value="#91000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.5240000" Value="#7F000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.7530000" Value="#72000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.9820000" Value="#63000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.2120000" Value="#56000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.4410000" Value="#3D000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.6710000" Value="#26000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.9000000" Value="#19000000"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="block1" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00" Value="#00000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.2290000" Value="Black"/>
                <SplineColorKeyFrame KeyTime="00:00:00.4590000" Value="#EF000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.6880000" Value="#E2000000"/>
                <SplineColorKeyFrame KeyTime="00:00:00.9180000" Value="#D3000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.1470000" Value="#C6000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.3760000" Value="#B7000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.6060000" Value="#AA000000"/>
                <SplineColorKeyFrame KeyTime="00:00:01.8350000" Value="#9B000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.0650000" Value="#8E000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.2940000" Value="#7F000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.5240000" Value="#72000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.7530000" Value="#63000000"/>
                <SplineColorKeyFrame KeyTime="00:00:02.9820000" Value="#56000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.2120000" Value="#3D000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.4410000" Value="#26000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.6710000" Value="#19000000"/>
                <SplineColorKeyFrame KeyTime="00:00:03.9000000" Value="#0C000000"/>
            </ColorAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>
    <UserControl.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard x:Name="ProgressAnimation_BeginStoryboard" Storyboard="{StaticResource ProgressAnimation}"/>
        </EventTrigger>
    </UserControl.Triggers>

    <Canvas x:Name="LayoutRoot" VerticalAlignment="Top" Height="70" Width="70">
        <TextBlock Text="Loading..." TextWrapping="Wrap" Canvas.Left="20.069" Canvas.Top="36.214"/>
        <Grid Width="10.734" Height="10.004" Canvas.Left="38.614" Canvas.Top="0.331">
            <local:Block x:Name="block" RenderTransformOrigin="0.5,4.3689" OpacityMask="#00000000" VerticalAlignment="Top" Height="10.004">
                <local:Block.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform Angle="180"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </local:Block.RenderTransform>
            </local:Block>
            <local:Block x:Name="block1" RenderTransformOrigin="0.5,4.3689" OpacityMask="#0C000000" VerticalAlignment="Top" Height="10.004">
                <local:Block.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX="0.99999999999999989" ScaleY="0.99999999999999989"/>
                        <SkewTransform/>
                        <RotateTransform Angle="-160"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </local:Block.RenderTransform>
            </local:Block>
            <local:Block x:Name="block2" RenderTransformOrigin="0.5,4.3689" OpacityMask="#19000000" VerticalAlignment="Top" Height="10.004">
                <local:Block.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform Angle="-140"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </local:Block.RenderTransform>
            </local:Block>
            <local:Block x:Name="block3" RenderTransformOrigin="0.5,4.3689" OpacityMask="#26000000" VerticalAlignment="Top" Height="10.004">
                <local:Block.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX="0.99999999999999989" ScaleY="0.99999999999999989"/>
                        <SkewTransform/>
                        <RotateTransform Angle="-119.99999999999999"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </local:Block.RenderTransform>
            </local:Block>
            <local:Block x:Name="block4" RenderTransformOrigin="0.5,4.3689" OpacityMask="#3D000000" VerticalAlignment="Top" Height="10.004">
                <local:Block.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX="0.99999999999999989" ScaleY="0.99999999999999989"/>
                        <SkewTransform/>
                        <RotateTransform Angle="-100"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </local:Block.RenderTransform>
            </local:Block>
            <local:Block x:Name="block5" RenderTransformOrigin="0.5,4.3689" OpacityMask="#56000000" VerticalAlignment="Top" Height="10.004">
                <local:Block.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX="0.99999999999999989" ScaleY="0.99999999999999989"/>
                        <SkewTransform/>
                        <RotateTransform Angle="-80"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </local:Block.RenderTransform>
            </local:Block>
            <local:Block x:Name="block6" RenderTransformOrigin="0.5,4.3689" OpacityMask="#64000000" VerticalAlignment="Top" Height="10.004">
                <local:Block.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform Angle="-59.999999999999993"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </local:Block.RenderTransform>
            </local:Block>
            <local:Block x:Name="block7" RenderTransformOrigin="0.5,4.3689" OpacityMask="#72000000" VerticalAlignment="Top" Height="10.004">
                <local:Block.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX="0.99999999999999989" ScaleY="0.99999999999999989"/>
                        <SkewTransform/>
                        <RotateTransform Angle="-40"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </local:Block.RenderTransform>
            </local:Block>
            <local:Block x:Name="block8" RenderTransformOrigin="0.5,4.3689" OpacityMask="#80000000" VerticalAlignment="Top" Height="10.004">
                <local:Block.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform Angle="-19.999999999999996"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </local:Block.RenderTransform>
            </local:Block>
            <local:Block x:Name="block9" OpacityMask="#8E000000" RenderTransformOrigin="0.5,4.3689" VerticalAlignment="Top" Height="10.004"/>
            <local:Block x:Name="block10" RenderTransformOrigin="0.5,4.3689" OpacityMask="#9C000000" VerticalAlignment="Top" Height="10.004">
                <local:Block.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform Angle="19.999999999999996"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </local:Block.RenderTransform>
            </local:Block>
            <local:Block x:Name="block11" RenderTransformOrigin="0.5,4.3689" OpacityMask="#AA000000" VerticalAlignment="Top" Height="10.004">
                <local:Block.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX="0.99999999999999989" ScaleY="0.99999999999999989"/>
                        <SkewTransform/>
                        <RotateTransform Angle="40"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </local:Block.RenderTransform>
            </local:Block>
            <local:Block x:Name="block12" RenderTransformOrigin="0.5,4.3689" OpacityMask="#B8000000" VerticalAlignment="Top" Height="10.004">
                <local:Block.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform Angle="59.999999999999993"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </local:Block.RenderTransform>
            </local:Block>
            <local:Block x:Name="block13" RenderTransformOrigin="0.5,4.3689" OpacityMask="#C6000000" VerticalAlignment="Top" Height="10.004">
                <local:Block.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX="0.99999999999999989" ScaleY="0.99999999999999989"/>
                        <SkewTransform/>
                        <RotateTransform Angle="80"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </local:Block.RenderTransform>
            </local:Block>
            <local:Block x:Name="block14" RenderTransformOrigin="0.5,4.3689" OpacityMask="#D4000000" VerticalAlignment="Top" Height="10.004">
                <local:Block.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX="0.99999999999999989" ScaleY="0.99999999999999989"/>
                        <SkewTransform/>
                        <RotateTransform Angle="100"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </local:Block.RenderTransform>
            </local:Block>
            <local:Block x:Name="block15" RenderTransformOrigin="0.5,4.3689" OpacityMask="#E2000000" VerticalAlignment="Top" Height="10.004">
                <local:Block.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX="0.99999999999999989" ScaleY="0.99999999999999989"/>
                        <SkewTransform/>
                        <RotateTransform Angle="119.99999999999999"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </local:Block.RenderTransform>
            </local:Block>
            <local:Block x:Name="block16" RenderTransformOrigin="0.5,4.3689" OpacityMask="#F0000000" VerticalAlignment="Top" Height="10.004">
                <local:Block.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform Angle="140"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </local:Block.RenderTransform>
            </local:Block>
            <local:Block x:Name="block17" RenderTransformOrigin="0.5,4.3689" OpacityMask="Black" VerticalAlignment="Top" Height="10.004">
                <local:Block.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX="0.99999999999999989" ScaleY="0.99999999999999989"/>
                        <SkewTransform/>
                        <RotateTransform Angle="160"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </local:Block.RenderTransform>
            </local:Block>
        </Grid>
    </Canvas>
</UserControl>

--------------------------Block
<UserControl x:Class="VISION.Block"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="Auto" Width="Auto">
    <Grid x:Name="LayoutRoot">
        <Path Fill="#FF5482A1" Stretch="Fill" RenderTransformOrigin="0.5,4.3689" Data="M291.15499,85.897525 C291.15499,85.897525 301.88917,85.87921 301.88917,85.87921 301.88917,85.87921 300.38339,94.355061 300.38339,94.355061 300.38339,94.355061 292.85366,94.355042 292.85366,94.355042 292.85366,94.355042 291.15499,85.897525 291.15499,85.897525 z"/>
    </Grid>
</UserControl>
--------------------------------
>iske alava or gana nhi ha kaya

------------------call function----------
 BackgroundLoading BL = new BackgroundLoading(Test);
 BL.Start();


Encryption or Decryption using TripleDES


private string TripleDESEncrypt(string tbMessage)
        {
            try
            {
                TripleDES threedes = new TripleDESCryptoServiceProvider();

                threedes.Key = StringToByte(tbKey, 24); // convert to 24 characters - 192 bits
                threedes.IV = StringToByte("12345678");
                byte[] key = threedes.Key;
                byte[] IV = threedes.IV;

                ICryptoTransform encryptor = threedes.CreateEncryptor(key, IV);

                MemoryStream msEncrypt = new MemoryStream();
                CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);

                // Write all data to the crypto stream and flush it.
                csEncrypt.Write(StringToByte(tbMessage), 0, StringToByte(tbMessage).Length);
                csEncrypt.FlushFinalBlock();

                // Get the encrypted array of bytes.
                byte[] encrypted = msEncrypt.ToArray();

                return ByteToString(encrypted);
            }
            catch (Exception ex)
            {
                return ex.Message.ToString();
            }

        }

        private string TripleDESDecrypt(string encryptedMessage)
        {
            try
            {
                TripleDES threedes = new TripleDESCryptoServiceProvider();

                threedes.Key = StringToByte(tbKey, 24); // convert to 24 characters - 192 bits
                threedes.IV = StringToByte("12345678");
                byte[] key = threedes.Key;
                byte[] IV = threedes.IV;

                ICryptoTransform decryptor = threedes.CreateDecryptor(key, IV);

                // Now decrypt the previously encrypted message using the decryptor
                byte[] encrypted = StringToByteDecimal(encryptedMessage);
                MemoryStream msDecrypt = new MemoryStream(encrypted);
                CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read);

                return ByteToString(csDecrypt);
            }
            catch (Exception ex)
            {
                return ex.Message.ToString();
            }
        }

How to fill year in Dropdown List


public void FillYearCombo(DropDownList ddl, int CurrYear, int PrevYear, int extraField)
        {
            try
            {
                ListItem ddlItem;
                ddl.Items.Clear();
                int YearDiff;
                int[] YearList;
                int Len = 0;

                YearDiff = CurrYear - PrevYear;

                int FinalYear = PrevYear + YearDiff;

                if (extraField == 1)
                {
                    YearList = new int[YearDiff + 2];
                    Len = YearList.Length - 1;
                }
                else
                {
                    YearList = new int[YearDiff + 1];
                    Len = YearList.Length;
                }

                for (int i = 0; i <= YearDiff; i++)
                {
                    YearList[i] = FinalYear - i;
                }

                for (int y = 0; y < Len; y++)
                {
                    ddlItem = new ListItem(YearList[y].ToString(), YearList[y].ToString());
                    ddl.Items.Add(ddlItem);
                }

                if (extraField == 1)
                {
                    ddlItem = new ListItem("Total", "Total");
                    ddl.Items.Add(ddlItem);
                }

            }
            catch
            {

            }

        }

Show Javascript messgae and when click ok then redirect to another page


 public static void ShowMsgWithRedirect(System.Web.UI.Page objPage, string msg, string pagename)
    {
        ScriptManager.RegisterStartupScript(objPage, objPage.GetType(), "", "alert('" + msg + "');window.location ='" + pagename + "';", true);
    }

    public static void ShowMessage(System.Web.UI.Page objPage, string msg)
    {
        ScriptManager.RegisterStartupScript(objPage, objPage.GetType(), "", "alert('" + msg + "');", true);
    }
    public static void ShowConMessage(System.Web.UI.Page objPage, string msg)
    {
        ScriptManager.RegisterStartupScript(objPage, objPage.GetType(), "", "Confirm('" + msg + "');", true);
    }

2012/11/18

How to fill combo box with view


public static void FillComboWithView(DropDownList ddl,  DataSet ds, string displayField, string valueField,string status)
    {
        DataView dvMember = ds.Tables[0].DefaultView;
        dvMember.RowFilter = status;
        dvMember.Sort = displayField;
        ddl.DataSource = dvMember;

        ddl.DataTextField = displayField;
        ddl.DataValueField = valueField;
        ddl.DataBind();
       
    }  

How to send email in .net


 public static void SendEmail(string fromEmail, string toEmail, string subject, string message)
    {
        try
        {
            MailMessage mailMessage = new MailMessage(fromEmail, toEmail);
            mailMessage.Subject = subject;
            mailMessage.Body = message;
            mailMessage.IsBodyHtml = true;
            SmtpClient client = new SmtpClient();
            client.Host = "smtp.gmail.com" ;
            client.EnableSsl = true;
            client.Credentials = new System.Net.NetworkCredential("test@gmail.com", "password");
            client.Send(mailMessage);

        }
        catch (Exception ex)
        {
            throw;
        }

    }

2012/09/15

What is difference between function and stored procedure

Functions 
---------- 
1) can be used with Select statement 
2) Not returning output parameter but returns Table variables 
3) You can join UDF 
4) Cannot be used to change server configuration 
5) Cannot be used with XML FOR clause 
6) Cannot have transaction within function 

Stored Procedure 
----------------- 
1) have to use EXEC or EXECUTE 
2) return output parameter 
3) can create table but won't return Table Variables 
4) you can not join SP 
5) can be used to change server configuration 
6) can be used with XML FOR Clause 
7) can have transaction within SP

 What is AI? Artificial Intelligence (AI) is the ability of machines or computer systems to perform tasks that normally require human intell...