Running a program while the computer is turned off [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I made a program. It tweets automatically every hour. What can I do to make it work when the computer is off. For example, there is an account called #everycolorbot, what is the working logic of this account?

You can do this with Azure Functions, where you only pay for compute time:
Create a new Functions project. Either in Visual Studio or On-Line. My preference is VS because I can keep the code in source control. You might need to open Visual Studio Installer and install Azure tools - either way, check out the docs at the Azure Functions link that I just posted here to make sure you're working with the latest info.
While creating the Functions project, choose a Timer trigger.
Take the defaults and it will create a new function project for you:
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
namespace TweetMyStuff
{
public static class MyTweetBot
{
[FunctionName("MyTweetBot")]
public static void Run([TimerTrigger("0 * * * *")]TimerInfo myTimer, ILogger log)
{
// your tweet logic here
}
}
}
Notice that I set the chron setting on the TimerTrigger parameter attribute to "0 * * * *" This will start the function every hour on the hour. Azure has chron expression syntax documentation, which matches the Linux syntax (so you can find more information by a web search).
Finally, deploy and monitor - you can visit the QuickStart for Visual Studio to help you get started in the right direction.

Related

"Hello world" c# program appear for a split of a second with Visual Studio [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
The code is correct I checked, and there is no real problem with my PC, my hardware is a bit old but it can do the job, so I'm guessing it's the settings of Visual Studio, I use the 2017 community edition and the solution is a consol application. the solution runs but I don't see my msg or anything, just the consol opening and closing real fast
You are probably running the application in debug, without something to prevent it to close as soon as the job gets done.
Basically, your code executes, and the application shuts because there is nothing else left to do.
Two solutions:
do as Štěpán Šubík recommands : put a Console.ReadKey();
start the application without debugging (Ctrl+F5 or menu Debug -> Start Without Debugging).
In both case, the console won't close itself automatically :).
check if you did everything correctly.
File -> New -> New Project
Visual C# on the left side,
Console Application,
give it a name and location.
Then write this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hello_world
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World");
Console.ReadKey();
}
}
}
The outpot is Hello World
It should stay in console and wait for pressing any button e.g.: k.
This works for my Microsoft Visual Studio Professional 2015 and I don't see a reason why it wouldn't work for you.

function repetition every 15 minutes c# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm doing some masks for SAP B1 using c#.
I'd need to know how to create a function that, automatically (for examples every 15 minutes), take some data and put its on a database.
The function is already done but how can I create the automatic execution in background?
Best regards and thanks in advance for the reply,
Lorenzo
Timer is what you need:
var timer = new System.Threading.Timer(
e => Method(),
null,
TimeSpan.Zero,
TimeSpan.FromMinutes(15));
This will call Method() every 15 minutes.
Timer info : https://msdn.microsoft.com/en-us/library/system.threading.timer.aspx
You could use Timer like #AmbroishPathak suggested. Also, as mentioned in the comments, you can use the Windows Task Scheduler to run your script or executable. The advantage of this is that the process won't be running in the background while it's not doing work.
You can see the details of how to schedule a task here.
The following answer describes this as well: windows scheduler to run a task every x-minutes?
To summarize the accepted answer there, you create the task to run once a day. After that, you can double-click on the task to bring up its Properties window and go to the "Triggers" tab. Under "Advanced Settings" you should be able to set it to run every x number of minutes.

Auto testing for Microsoft Bot Framework [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm working now on my first bot with Microsoft Bot Framework, with ASP.NET.
After manually testing with the bot emulator, I'm looking for the best method to create automatic testing for the bot.
Considering two problems:
What is the best tool to automate such tests?
What is the best method to test a dialog that can return different answers to the same input?
One alternative is doing functional tests using DirectLine. The caveat is that the bot needs to be hosted but it's powerfull. Check out the AzureBot tests project to see how this works.
Another alternative, is doing what the BotFramework team is doing for some of their unit tests.
If you are using Dialogs, you can take a look to the EchoBot unit tests as they are simple to follow.
If you are using Chain, then take a look to how their are using the AssertScriptAsync method.
https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Tests/Microsoft.Bot.Builder.Tests/ChainTests.cs#L360
https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Tests/Microsoft.Bot.Builder.Tests/ChainTests.cs#L538
If you are looking for a way to mock up Luis Service, see this.
You may want to consider Selenium. Selenium is web browser automation software allowing you to write tests that programmatically read and write to the DOM of a web page. With a Selenium script you can:
login on any channel that provides a web client (and most of them do: WebChat, Telegram, Skype, Facebook, for example)
start a conversation with your bot
perform operations such as post a message to the chat and wait for a reply
test whether the reply is what you expected.
For automated testing of bots in Node.js, using ConsoleConnector in the same way as the tests in BotBuilder on GitHub works well, e.g. take a look at https://github.com/Microsoft/BotBuilder/blob/master/Node/core/tests/localization.js:
var assert = require('assert');
var builder = require('../');
describe('localization', function() {
this.timeout(5000);
it('should return localized prompt when found', function (done) {
var connector = new builder.ConsoleConnector();
var bot = new builder.UniversalBot(connector);
bot.dialog('/', function (session, args) {
session.send('id1');
});
bot.on('send', function (message) {
assert(message.text === 'index-en1');
done();
});
connector.processMessage('test');
});
...etc...

Execution time testing for c# method [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a cs page with a few methods. When I try to load that page it takes a long time. Is there any way to identify how long each method is taking to fetch data? Instead of debugging is there any way of capturing the time spans?
Any tool or any other suggestions?
Yes you can enable Tracing to check which event takes how much time.
set Trace = true in the Page directive.
Also you can write custom trace line
Trace.Write("Method 1 begin");
//Call you method thats taking time.
CalculateSomething();
Trace.Write("Method 1 begin");
And you can use stopwatch to check the exact time.
using System.Diagnostics;
Stopwatch St = new Stopwatch();
St.Start();
//Call your method
Trace.Write("Stopwatch " + St.ElapsedTime.toString());
St.Stop();
The Visual Studio Profiling Tools let developers measure, evaluate, and target performance-related issues in their code. These tools are fully integrated into the IDE to provide a seamless and approachable user experience.
Profiling an application is straightforward. You begin by creating a new performance session. In Visual Studio Team System Development Edition, you can use the Performance Session Wizard to create a new performance session. After a performance session ends, data gathered during profiling is saved in a .vsp file. You can view the .vsp file inside the IDE. There are several report views available to help visualize and detect performance issues from the data gathered.
MSDN REFERENCE

How to sync system clock with global date/time? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
My system clock is going crazy randomly at any moment and changing the system clock's date/time to a random one. It's not the lithium battery nor a virus because I checked. Also it's not something from the Windows.System.Time itself.
I want to create a process that will, on an interval, check to see if the system clock's date/time matches the global date/time and if not, it would sync.
I need this to run in the background. I am not even sure if a Windows process is correct way to accomplish this. I am open to any other solutions as well.
Create a new c# empty project. Click on the project and go to Properties change the output type to Windows Application (This will remove the console).
Create a new class example: Example.cs
Write the static entry point eg:
public class Example
{
static void Main(string[] args)
{
}
}
Insert your code in the Main routine.
This will create a process that contains no console/window/service.
I'm guessing this is what you want.

Categories