queryPerformanceFrequency in C# UWP - win-universal-app

I would like to call queryPerformanceFrequency function in Windows 10 C# UWP app.
[DllImport("Kernel32.dll")]
private static extern bool QueryPerformanceFrequency(out long lpFrequency);
does not seem to work
How should I do it?
Thanks!

Related

How to push logs to splunk from log4net in .net core 6

We are migrating from .net framework to .net core framework for our api.
We are trying to use log4net framework for logging Info and Error and then pushing them all to splunk since it was used in the existing api on .net framework.
But here in .net core im not getting a proper way or documentation to use log4net for logging and pushing the data to splunk. I have tried searching a lot and still not able to complete the implementation.
Can anyone please help me in this regard.
Thank you.
Vishwa
I have added configs for log4net and a logger class with methods, which i can use to log the Info and Error like below
namespace ABC
{
using System.Diagnostics;
using System.Reflection;
using log4net;
public static class Logger
{
private static readonly ILog Log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public static void Info(this string className, string message)
{
log4net.LogicalThreadContext.Properties["ActivityId"] = Trace.CorrelationManager.ActivityId;
log4net.LogicalThreadContext.Properties["LogType"] = className;
Log.Info(message);
}
public static void Error(this string className, string message)
{
log4net.LogicalThreadContext.Properties["ActivityId"] = Trace.CorrelationManager.ActivityId;
log4net.LogicalThreadContext.Properties["LogType"] = className;
Log.Error(message);
}
}
}
Now im stuck with the part to push logs to splunk . Any help would be appreciated

Azure WebJob runtime unable to map virtual key using MapVirtualKey (user32.dll)

.Net Console Application works just fine until it is uploaded as Azure WebJob to Azure website. Code to replicate:
using System;
using System.Runtime.InteropServices;
using System.Windows.Input;
namespace ConsoleApplication2
{
class Program
{
[DllImport("user32.dll")]
private static extern uint MapVirtualKey(uint uCode, uint uMapType);
static void Main()
{
foreach (uint c in new uint[] {18, 31})
{
var mapped = (int) MapVirtualKey(c, 1);
Console.WriteLine($"{mapped} : {KeyInterop.KeyFromVirtualKey(mapped)}");
}
}
}
}
Expected output:
69 : E
83 : S
Actual output:
-1073741790 : None
-1073741790 : None
Not sure where to go from here. does it mean that access is denied for this api call?
The reason this doesn't work is that the MapVirtualKey API is blocked by the Azure Web App sandbox. You can learn more about the sandbox on https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox. See in particular this paragraph:
For the sake of radical attack surface area reduction, the sandbox prevents almost all of the Win32k.sys APIs from being called, which practically means that most of User32/GDI32 system calls are blocked. For most applications this is not an issue since most Azure Web Apps do not require access to Windows UI functionality (they are web applications after all).

monotouch implement singleton Admob ads

I am trying to implement Admob ads in my App.
After a few tests I made with previous apps, i have realized that a static Ad between screens usually make a better eCPM.
So I have searched a bit and found a post on implementing a singleton for Admob - unfortunetally it's written in objective-C.
I wonder if someone implemented something similar in monotouch or maybe implemented something which will get the same result.
This is the relevant post:
Creating A GADBannerView Singleton in AdMob Applications
Thanks for your help!
I would just make a static variable using Lazy<T>:
private static Lazy<GADBannerView> _adBanner = new Lazy<GADBannerView>(() => new GADBannerView());
public static GADBannerView AdBanner
{
get { return _adBanner.Value; }
}
You could put this in your AppDelegate, or just in a static class.

get main window

I am trying to get the main Window of an application written C#.
Application.MainWindow Property does not work :(
uses:
using System;
using System.Windows;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using System.Collections.Generic;
using My;
using MyDialogs;
using System.Xml.Serialization;
using System.Runtime.InteropServices;
using System.Windows.Input;
using System.Windows.Media;
using System.Threading;
using System.Windows.Interop;
Do you have a line of code like this in your application anywhere?
Application.Run(new Form1());
Where Form1 is the type of the form that is created when your application starts. This is code created by default when you create a new Windows Forms application. If you want to remember that instance, you just need to store the result in a variable accessible by other classes. For example:
static class Program
{
public static Form1 MainForm;
// ...
static void Main()
{
// ...
MainForm = new Form1();
Application.Run(MainForm);
}
}
I think your application type is Windows Forms application. That follows from you post:
I have this
private static void Main(string[] args) {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
So, you can't use MainWindow object (type of System.Windows.Window), because it's using in WPF. Create new WPF project, and you can acces Application.MainWindow property.

Support for Long Running Operations using the MOSS Publishing Infrastructure

I have used the Long Running Operation capability within the Publishing Infrastructure within MOSS (SharePoint) in the past, and am curious if anyone knows if this is a supported technique for having custom long running operations within SharePoint.
When using this technique, you inherit from Microsoft.SharePoint.Publishing.Internal.LongRunningOperationJob which seems to indicate that it is not supported for custom use, but I seem to recall (maybe I dreamt?) that long running processes was a marketed feature of MOSS.
Any ideas?
SharePoint Timer Jobs are described in MSDN Journal April edition
http://msdn.microsoft.com/en-us/magazine/dd569748.aspx
Good question Kirk! I have recently also experienced the need to implement long running jobs in SharePoint. But the LongRunningOperationJob was not an option as it also needed to work with a plain WSS 3.0 deployment. I simply ended up spawning a new thread from the Web request and redirecting to an ASPX page with an AJAX enabled progress bar updating itself every other second. It works perfectly well and can run as long as needed. Only downside is that an IISRESET will kill it for good. Another possibility could be to implement long running jobs using a custom SharePoint Timer Job.
SPLongOperation is a very simple way to do a long running operation. Much simpler than the Publishing.LongRunningOperationJob and uses the same infrastructure.
Ever woundered how microsoft create the nice longrunning process windows works in SharePoint 2007?
SPLongOperation is the class to use. It has 2 important methods
Begin and End;
All your code that runs for a long time is placed between begin and end.
Below is a sample class.
It is almost to simple and just works :-)
using System;
using System.Web;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
namespace CreateLongOperation
{
public class LongRun : System.Web.UI.Page
{
protected Button buttonOk;
protected void Page_Load(object sender, EventArgs e)
{
buttonOk.Click += new EventHandler(buttonOk_Click);
}
void buttonOk_Click(object sender, EventArgs e)
{
SPLongOperation operation = new SPLongOperation(this.Page);
operation.Begin();
// do long operation code here...
System.Threading.Thread.Sleep(6000);
operation.End("http://sps/_layouts/Mynewpage.aspx");
}
}
}

Resources