|
This is a terrible suggestion. You're not supposed to use exceptions to drive the flow of control. Also, doing this hides what could be a variety of exceptions that that code could cause.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Although both of the listBoxes **AllowDrop=true** listBox2 does not allow me to drop an item from listbox1 into listBox2.
VS 2022 does not give any error, warning or exception handling problem. The problem is that this code does not do what it supposed to do. It does not let me carry 1 item from listBox1 to listBox2.
C#:
namespace LISTBOX_fareileSURUKLEbirakDRAGDROP_Olaylari
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
listBox1.AllowDrop = true;
listBox2.AllowDrop = true;
int i;
for(i = 0; i < 10; i++)
{
listBox1.Items.Add(i);
}
}
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
if (listBox1.Items.Count == 0) return;
string deger = listBox1.Items[listBox1.IndexFromPoint(e.X,e.Y)].ToString();
if (DoDragDrop(deger, DragDropEffects.All) == DragDropEffects.All)
listBox1.Items.RemoveAt(listBox1.IndexFromPoint(e.X, e.Y));
}
private void listBox2_DragOver(object sender,DragEventArgs e)
{
e.Effect= DragDropEffects.All;
}
private void listBox2_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.StringFormat))
listBox2.Items.Add(e.Data.GetData(DataFormats.StringFormat));
}
}
}
What do you think is the problem here?
modified 7-Oct-22 7:40am.
|
|
|
|
|
Probably, it's not a string.
Use the debugger to check the e.Data value and see exactly what is going on.
"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!
|
|
|
|
|
This simple code gives Exception Handling Error:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Label_LinkLabel_TextboxKONTROLLERI
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
LinkLabel dynamicLinkLabel = new LinkLabel();
private void Form2_Load(object sender, EventArgs e)
{
dynamicLinkLabel.BackColor = Color.Red;
dynamicLinkLabel.ForeColor = Color.Blue;
dynamicLinkLabel.Text = "I am a Dynamic LinkLabel";
dynamicLinkLabel.TextAlign = (ContentAlignment)HorizontalAlignment.Center;
dynamicLinkLabel.Text += " Appended text";
dynamicLinkLabel.Name = "DynamicLinkLabel";
dynamicLinkLabel.Font = new Font("Georgia", 16);
Controls.Add(dynamicLinkLabel);
dynamicLinkLabel.Name = "DynamicLinkLabel";
string name = dynamicLinkLabel.Name;
dynamicLinkLabel.Location = new Point(20, 150);
dynamicLinkLabel.Height = 40;
dynamicLinkLabel.Width = 300;
dynamicLinkLabel.BackColor = Color.Red;
dynamicLinkLabel.ForeColor = Color.Blue;
dynamicLinkLabel.BorderStyle = BorderStyle.FixedSingle;
dynamicLinkLabel.ActiveLinkColor = Color.Orange;
dynamicLinkLabel.VisitedLinkColor = Color.Green;
dynamicLinkLabel.LinkColor = Color.RoyalBlue;
dynamicLinkLabel.DisabledLinkColor = Color.Gray;
dynamicLinkLabel.LinkArea = new LinkArea(0, 22);
dynamicLinkLabel.Links.Add(24, 9, "http://www.c-sharpcorner.com");
dynamicLinkLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(LinkedLabelClicked);
}
private void LinkedLabelClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
dynamicLinkLabel.LinkVisited = true;
System.Diagnostics.Process.Start("http://www.c-sharpcorner.com");
}
}
}
The code above has been taken from this website: https:
Here is the exception:
System.ComponentModel.Win32Exception: 'An error occurred trying to start process 'http:
Here is the CS8604 Warning: https:
I did not understand what causes this. How can I solve this problem?
|
|
|
|
|
A URL is not a process. Look at the documentation Process.Start Method (System.Diagnostics) | Microsoft Learn[^]
And if code from another site is "broken" then you should really be posting the question on the site you got it from
Edit: Assuming the code works for the original author, then I can only assume he has some default set so that his preferred browser automatically opens but you do not. Try using the name of your favourite browser as the process name, passing that URL as a parameter
|
|
|
|
|
Your errors suggest you're using .NET Core or .NET 5, 6, or 7. Unlike in the .NET Framework, .NET Core and .NET do not set the UseShellExecute to true by default - you need to specify it explicitly:
private void LinkedLabelClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
dynamicLinkLabel.LinkVisited = true;
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
{
FileName = "http://www.c-sharpcorner.com",
UseShellExecute = true,
});
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Is there a free licensing solution for .NET?
It can be hosted on the cloud or self-hosted.
Requirements: works with C# and unlimited licenses.
Can be hosted anywhere, except in the app or in a website (Only the app can access the product keys)
Thanks!
|
|
|
|
|
Why would someone not charge if it had all those features?
This is simply Google legwork and has nothing to do with "programming in C#".
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Cloud-hosted will always cost money because cloud doesn't come free.
You host find a solution that you can host on your own servers, but that's not going to be free either. Power to run servers and ISP costs money.
"Can be hosted anywhere, except in the app or in a website", well, where the hell else are you going to host the servers that hold the licenses?
Basically, a "free" license server doesn't exist.
|
|
|
|
|
I am working on an app that uses a Service Locator. Then, someone above me decided that a service locator is "an anti-pattern". I'm guessing they read this or some other bright spark's blog.
There's another excellent discussion here.
I've been using a service locator for a long time with no issues. I'd like to hear what everyone else thinks. Is there any reason NOT to use a service locator?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
The "service" is still just an object. It's object-oriented programming with a nod to component-based programming. You write more code (interfaces). Pointless when the caller deals with only one type; i.e. is not of the switchboard variety. It then become a chore adding to everything, because that's the "standard".
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
While I agree with you, I'm not sure if you answered my question. Any real reason NOT to use them?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Gerry Schmitz wrote: You write more code (interfaces). Pointless when the caller deals with only one type
I assume you never write unit tests then?
(Yes, I'm aware it's possible to generate a mock of a class for a test. But it's generally easier to generate a mock for an interface, since you don't have to worry about inheriting from a class which might produce undesirable side-effects in your tests.)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
From the top of my head:
Dependency injection makes it a bit easier to write unit tests - you do not have to mock the service locator and you can see straight from the constructor what the dependencies are.
It is also better failing early. It can often detect missing dependencies when you spin up the app, instead of when some obscure case happens 3 weeks after deploying to production. It's not guaranteed for complex registrations (factories) but the simple stuff it will do.
I would always use DI for new projects, but it's unlikely I would spend time refactoring old SL based code. I can say from the code base I have inherited: If you use both in the same application everything becomes a mess.
Edit: Followed the link and read his "summary" - which is basically identical to my reply.
|
|
|
|
|
That link suggests that DI has the same issue of service locator with regard to runtime discovery of failure.
That is only true if you equate "app will not launch runtime" with "app conditionally crashes/errors runtime".
Those are not the same beast. The OA at the link wraps up with that, and lots of people chime in with similar reasons.
I think the question should be is there any reason NOT to use DI? There are clearly drawbacks to SL even if someone doesn't care about them. "Anti-pattern"? That's probably a bit of hot air blown hard. But DI is better.
|
|
|
|
|
It's been weeks of searching everywhere but couldn't find any help and finally i'm posting my query here.
I'm not finding a way to integrate Skype Personal (Not Skype Business/Lync) in my c# application. I just want to receive Skype messages on my application. I have tried using Skype4com Library but it has discontinued and does not support the latest Skype and LYNC API also works only with Skype for business and same with Skype Web SDK as it does not work with Skype personal. I also tried the method to fetch the details through Skype local database but latest version of Skype doesn't store anything locally.
Note: There are still some applications with Skype integration that I know but I don't know how they do that.
|
|
|
|
|
I guess that's the difference between "free" and "not free". You can spend (waste) more time looking for free than paying for not free. And, who is the ultimate customer.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
What do you mean with free and not free?
|
|
|
|
|
I guess the "not free" means one must pay some mony for it.
|
|
|
|
|
There aren't any paid api's too.
|
|
|
|
|
Integration for the personal (free) version is not supported, you need to be using the business (not free) verion to be able to extend/integrate its functionality. I recall spending many hours searching for a solution before the bank gave up and forked over the money to MS for the business version.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
I appreciate your comment but there are still applications manage to track skype personal messages. I'm so curious to find how they do that.
|
|
|
|
|
Hi,
Why Sample #2 is "Bets Practices". Second sample include "await" keyword on the same line with Async Method. Both codes are blocking Thread. Any idea? thanks...
Sample #1
var products = _context.Products.ToList();
Sample #2
var products = await _context.Products.ToListAsync();
|
|
|
|
|
It gets a complicated, but basically the await call spins off a second thread to execute the long running task, and effectively suspends the method until it's complete. But ... the thread that executed await can continue as if the method had finished.
This is handy if you want to run a long task from the main (UI) thread while the UI remains responsive.
For example, if you run this code:
private void MyOtherButton_Click(object sender, EventArgs e)
{
Debug.WriteLine("Before Sleep");
Thread.Sleep(10000);
Debug.WriteLine("After Sleep");
}
Your console will print "Before Sleep", wait ten seconds and print "After Sleep" - but your user can't do anything else with your app in the mean time.
But this code:
private async void MyOtherButton_Click(object sender, EventArgs e)
{
Debug.WriteLine("Before Sleep");
await Task.Run(() => Thread.Sleep(10000));
Debug.WriteLine("After Sleep");
}
Prints the same things, but your user can carry on working - your UI remains working.
Have a look here: https://www.pluralsight.com/guides/understand-control-flow-async-await[^] - it explains it pretty well, and shows examples.
"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!
|
|
|
|
|
OriginalGriff wrote: the await call spins off a second thread to execute the long running task
A common misconception.
await is almost nothing to do with multi-threading; it's more about using IO-completion ports to avoid keeping a thread spinning whilst it waits for an external resource to respond.
OriginalGriff wrote:
private async void MyOtherButton_Click(object sender, EventArgs e)
{
Debug.WriteLine("Before Sleep");
await Task.Run(() => Thread.Sleep(10000));
Debug.WriteLine("After Sleep");
} Aside from the fact that you should avoid async void wherever possible[^], spinning up a background thread just to make it sleep seems like a bad idea.
private void MyOtherButton_Click(object sender, EventArgs e)
{
_ = MyOtherButton_Click_Async();
}
private async Task MyOtherButton_Click_Async()
{
Debug.WriteLine("Before Sleep");
await Task.Delay(10000);
Debug.WriteLine("After Sleep");
} See David Fowler's explanation of the _ = SomeTaskReturningMethod(); construct under the "Timer callbacks" heading: AspNetCoreDiagnosticScenarios/AsyncGuidance.md at master · davidfowl/AspNetCoreDiagnosticScenarios · GitHub[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
modified 20-Sep-22 11:11am.
|
|
|
|