In Power Bi, there is challenge to get page details when changing the pages. In Angular/JavaScript, powerBI client provides event handling to manage this. For this page changes, we have "pageChanged" event. Below sample code will help us to get events on page changes, so that you can capture bookmark if needed on previous page names etc.,
Important codings & concepts in web & window applications using microsoft technologies.
Friday, July 21, 2023
How to get previous page details in page change event on embedded PowerBI report
Friday, January 13, 2023
How to cancel any running task by wait for sometime in C#
Problem Statement: In some real time scenario, you may need to cancel some long running tasks in certain time interval and then proceed.
Here in below example, i am calling some infinite time method and am not sure when it will be completed. So i am making 30 seconds maximum to wait and cancelling it.
RunSomeTestJob();
string RunSomeTestJob()
{
string result = "";
//loop your logic
try
{
Console.WriteLine("Running Job Started " + DateTime.Now.ToString());
// Create CancellationTokenSource.
var source = new CancellationTokenSource();
// ... Get Token from source.
var token = source.Token;
var someTask = Task.Run(() =>
{
result =
infinteJobWork(token);
}, token);
someTask.Wait(30 *
1000);
//someTask.Dispose();
source.Cancel();
}
catch (Exception ex)
{
//suppress error and proceed
//log somewhere
}
Console.Write("Running Job Completed " + result + DateTime.Now.ToString());
Console.Read();
//proceed with next steps
return result;
}
string
infinteJobWork(CancellationToken token)
{
//Short running Job - Fixed timing
//for (int i = 0; i < 3; i++)
{
//Long running Job - Indefinite time
while (true)
{
//TODO: make some api call or some work to external api
Console.WriteLine("Running Job : " + DateTime.Now.ToString());
Thread.Sleep(5 *
1000);
// See if we are canceled from our CancellationTokenSource.
if
(token.IsCancellationRequested)
{
Console.WriteLine("Job cancelled");
return "Job cancelled";
}
}
}
//return "Job done";
}
Thursday, May 14, 2020
How to ignore property conditionally during JSON serialization
Declare some values
Now serialize it for json string
Now lets see how to ignore the properties conditionally, you can choose either one of these options.
Option 1: Use ShouldSerialize property inside class itself like below. But you need add individual shouldSerialize property for each class property.
Create Resolver Class,
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Linq;
using System.Reflection;
...
Monday, April 22, 2019
C# - Pdf rotate using iTextSharp
C# - Pdf split using iTextSharp
}