|
You can't run C# code on a client - it needs the right .NET framework and that may not be installed.
And besides, if you didn't have a server you would have nothing to load the HTML from in the first place!
I think you need to have a good long think about exactly what you are trying to do, and perhaps research some to find out how these things work. I get the feeling you are just guessing, and that's not a good idea.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You probably need to run your HTML in a web browser control, in a Windows Forms or WPF app, and then hook up to events in the HTML. "Tagging" hidden content with "scripting code" is an added option.
internet explorer - Hooking IE Events in C# - Stack Overflow
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Can a button in html call any function at all? If so, in what programming language? Could I in that case make that programming language call a .dll consisting of my compiled C# code?
|
|
|
|
|
A button is "dumb"; it doesn't "call anything and everything"; it needs to be "hooked up"; regardless of the platform. You're interfacing with a "document object model". An API.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
An HTML button cannot directly call a C# method. The button is in one execution environment and the C# code is in another, even if your HTML and C# code are running client-side.
It sounds like you're trying to use an HTML page as an interface for a desktop app. That's a bad idea.
It can work, but there's a steep price. You'd have to host the ASP.NET runtime in your desktop app. This adds a LOT of overhead and complexity to your app, so it's usually not worth it.
If you're going to go through this pain, it's actually easier to just write up the app as an actual website and host in on the internet.
|
|
|
|
|
You are correct that I want a web-browser with an html-file to be the GUI of a (very basic) application that displays text and pictures with basic filter functionality. If I divide it into an html-file and a server written in C#, is it then possible to do both the client-browsing and server-hosting on the same laptop computer, without access to the Internet?
|
|
|
|
|
Yes it's possible, though, I wouldn't recommend it.
Google for "C# host ASP.NET in Windows Forms application".
|
|
|
|
|
arnold_w wrote: without access to the Internet
If you consider the Internet to be things outside of your PC then the answer is Yes. However, even if you keep everything on your PC, you will need the PC to host a web server but that can be local to the PC only. So the PC can be stand-alone and not connected to the Internet. This is actually common practice - when you write a web application, you run it on a locally hosted web server and only when all testing has been completed you would publish it to an intranet or extranet web server.
|
|
|
|
|
You should read some CodeProject articles starting with Sample HTTP Server Skeleton in C#[^].
EDIT: alternative article: Embedded .NET HTTP Server[^]
I read it again only yesterday; today the link (as many others to CP) seems defective, hope it will get fixed soon.
Using those techniques you can combine any C# functionality you want with an HTTP server of your own, allowing you to get one or more "web pages" from it by using an appropriate URL. Technically speaking your C# code is running on the server, which can reside on the same PC your browser/client is running on.
I've done this a couple of times, it works just fine.
BTW it is advanced stuff and will need some studying...
PS: and then Microsoft is working on its Blazor | Build client web apps with C# | .NET[^] technology where .NET code will actually run inside any browser anywhere, but AFAIK that isn't really available yet.
Luc Pattyn [My Articles]
If you can't find it on YouTube try TikTok...
modified 6-Sep-20 7:38am.
|
|
|
|
|
One of our teachers in C# has asked us why this code is generating error:
class MainClass {
public static void Main (string[] args) {
int a, b;
int soma;
a = 10;
b = 5;
soma = a + b;
Console.WriteLine("Soma ="soma);
}
}
__________
The error it returns is:
main.cs(15,26): error CS1525: Unexpected symbol `soma'
Which means there is something wrong in the "Console.WriteLine" line (line 15 in my code).
Thing is, I can't understand what is missing. Can any seniors point out to me?
|
|
|
|
|
You are trying to combine a string with a variable, your console.writeline needs to display a string it cannot work out what Console.WriteLine("Soma ="soma); is. Take a look at the .ToString() method on the variable.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
I'm sorry, so my console.writeline should be Console.WriteLine.Tostring("Soma =" soma) ???
Or if not, could you post the correct sequence?
I just realized... all we need is a comma, right? Between the string side and the Variable side.
does
Console.WriteLine("Soma =", soma);
works?
modified 4-Sep-20 21:46pm.
|
|
|
|
|
You did not understand what was written, apply the ToString() method to the variable soma. Then you need to concatenate the strings.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
So the concatenation was the thing I wasn't doing... aha.
Console.WriteLine("Soma =" + soma);
I got it now. I needed the + symbol between the string and the variable. Now the code worked on my console at least.
|
|
|
|
|
Concatenation is just one way to fix it:
Console.WriteLine("Soma = " + soma); There is also formatting:
Console.WriteLine("Soma = {0}", soma); Where "{0} " says "use the first (or zeroth since C# indexes are zero based) parameter value here".
Or interpolation:
Console.WriteLine($"Soma = {soma}"); Where the "$ " prefix enables interpolation, and then the "{" and "} " characters delimit the actual values to be used in the string.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
On naming; the result variable is not "som of a", but "som of a and b". So, something like "SomAB" might be more appropriate. It'd also be preferable to use English in source, as that makes your code more accessible. Hence, "SumOfAandB".
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I have this function
private async Task<int> SearchForAllNumbers(int num = -1)
{
if (num == -1)
DisplayLoadingMessage(true, GetString(Resource.String.Common_SearchTitle), GetString(Resource.String.Common_SearchMessage));
dates = DateFunctions.GetSelectedDates(DateFrom, DateTo);
var list = string.Empty;
var klirwseis = ", Κληρωσεις: ";
if (num == -1)
list = ListTextView.Text;
else
list = num.ToString();
var nums = list.Split(',').Select(Int32.Parse).ToList();
if (seperateCheckBox.Checked)
{
DisplayLoadingMessage(false);
seperateCheckBox.Checked = false;
for (int k = 0; k < nums.Count; k++)
{
await SearchForAllNumbers(nums[k]);
}
return -1;
}
var totalCoutner = 0;
for (int datesPos = 0; datesPos <= dates.Count; datesPos++)
{
... Do some calculations
}
HistoryTextView.Text = "Ημερομηνία: " + dates[datesPos] + ", Λίστα: " + list + ", Κληρώθηκε: " + totalCoutner + " φορές" + HistoryTextView.Text;
if (showListsCheckBox.Checked)
HistoryTextView.Text = klirwseis + HistoryTextView.Text;
}
DisplayLoadingMessage(false);
HistoryTextView.Text = ".\n" + HistoryTextView.Text;
return totalCoutner;
return 0;
}
And i want to be able to cancel it when its running so i have created this function
private async Task SearchFoNumbersAsync()
{
ActiveCancellationTokenSource = new CancellationTokenSource();
DrawResultsTypeEnum searchType = (DrawResultsTypeEnum)ShowResultsSpinnerPosition;
var task = Task.Run(async () =>
{
if (searchType == DrawResultsTypeEnum.AllNumbers)
await SearchForAllNumbers();
else if (searchType == DrawResultsTypeEnum.AnyWinningCombination)
await SearchAnyWinningCombination();
SaveHistory();
}, ActiveCancellationTokenSource.Token);
try
{
await task;
}
catch (System.OperationCanceledException e)
{
Console.WriteLine($"{nameof(System.OperationCanceledException)} thrown with message: {e.Message}");
DisplayLoadingMessage(false);
}
finally
{
ActiveCancellationTokenSource.Dispose();
DisplayLoadingMessage(false);
}
}
To be able to run it from Task.Run and to be able to cancel it. The code doesnt work however
I have debug it and when it reach the
try
{
await task;
}
Stays there forever, the
SearchForAllNumbers() or
SearchAnyWinningCombination() are not accessed at all.
i'm not sure what i have done wrong.
|
|
|
|
|
Keep taking code out until it works, then start adding it back in. If nothing works, start over.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
thanks, this helped, i found the reason of that but now i see that if i cancel the task, all the already running functions will keep running. im not sure if the best approach is to add some if (token.iscancellationrequested) or to make all the functions to tasks that can take a token
|
|
|
|
|
|
I was reading this today but it looks to me like a worst idea of having a task that can take a cancellation token so i will try to find more approaches on how to cancel task and its childrends
|
|
|
|
|
If you don't "like" MS samples, you're going to be in for a lot of headaches.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
a general sample might not be the best solution for every situation. my code in the first post also is based on MS samples
|
|
|
|
|
I decided write a .Net Core Windows App to track my Amazon and EBay sales.
Choose .Net Core 3.1, and the app works pretty damn good. It's suppose to be new, with all these benefits. I can't remember the benefits, maybe one of them being your app runs in a container sort of like docker, and can run on other platforms such as MacOs, Linux.
Also chose Mongo as the DB.
I'm fuzzy on the DB stuff here. I wrote a respository using .Net Core Web techniques, in which I created IOrdersRespository and OrdersRepository, which might of been a mistake. In a .Net Core web app, you register the respository in startup, and use the repository in the controller. But I have no clue if I'm suppose to do sort of the same thing in a Windows app.
I searched around on Google, but it pulls up all the web subjects.
I was thinking of going back and dumping the IOrdersRespository and just use a straight class, and make the functions static.
But then I have to call up the context in every db function.
Any insight would be helpful.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Mongo DB is a "document" database I think you would be better served using a relation DB, you are not storing documents you are parsing and storing data!
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|