|
Have you found solution for this issue ? I am facing similar issue.
|
|
|
|
|
I have created a Retry function (using Rx with Rx-main and Rx-xaml packages from NuGet) that uses a timer to Retry the function if an error appears, but if it is not successful within a given timeframe, the presses is aborted.
I use the functiuon like shown below:
textBox.Text = "";
Thread.CurrentThread.Name = "UI Thread";
IScheduler thread1 = new NewThreadScheduler(x => new Thread(x) { Name = "Thread1" });
TimeSpan RetryMaxTime = new TimeSpan(0, 0, 0,0,5);
Observable.Create<int>(o =>
{
Console.WriteLine("Created on " + Thread.CurrentThread.Name);
o.OnNext(1);
o.OnError(new Exception("Something random just happened"));
o.OnCompleted();
return Disposable.Create(() => { });
})
.SubscribeOn(thread1)
.Retry(RetryMaxTime)
.ObserveOnDispatcher()
.Subscribe(
x =>
{
textBox.Text += x.ToString() + Environment.NewLine;
}
, ex => textBox.Text += ex.Message
, () => { textBox.Text += "Completed on " + Thread.CurrentThread.Name; }
);
}
Basically, I used the WeakSubscription code to create the function:
public static class MyExtensions
{
public static IObservable<TItem> Retry<TItem>(this IObservable<TItem> collection,TimeSpan ExceptionTimeout)
{
return Observable.Create<TItem>(obs =>
{
var weakSubscription = new WeakSubscription<TItem>(collection, obs, ExceptionTimeout);
return () =>
{
weakSubscription.Dispose();
};
});
}
public class WeakSubscription<T> : IDisposable, IObserver<T>
{
private readonly WeakReference reference;
private readonly IDisposable subscription;
private Exception LastError;
private bool EndRetry = false;
private bool disposed;
private System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
public WeakSubscription(IObservable<T> observable, IObserver<T> observer, TimeSpan ExceptionTimeout)
{
this.reference = new WeakReference(observer);
var interval = Observable.Interval(ExceptionTimeout);
interval.SubscribeOn(Scheduler.CurrentThread).Subscribe(x =>
EndRetry = true);
this.subscription = observable.Retry()
.Catch<T>(e=>e)
.Subscribe(this);
}
IObservable<T> ExceptionHappened(Exception ex)
{
return null;
}
void IObserver<T>.OnCompleted()
{
var observer = (IObserver<T>)this.reference.Target;
if (observer != null)
observer.OnCompleted();
if (this.EndRetry)
this.Dispose();
}
void IObserver<T>.OnError(Exception error)
{
var observer = (IObserver<T>)this.reference.Target;
LastError = error;
if (observer != null)
observer.OnError(error);
if (this.EndRetry)
this.Dispose();
}
void IObserver<T>.OnNext(T value)
{
var observer = (IObserver<T>)this.reference.Target;
if (observer != null)
observer.OnNext(value);
if (this.EndRetry)
this.Dispose();
}
public void Dispose()
{
if (!this.disposed)
{
this.disposed = true;
this.subscription.Dispose();
}
}
}
}
As you can see, if the operation is unsuccessful after the tries, I'd like to get the Exception that was thrown inside the Retry function. My question is simply, how can I get the error thrown, or is there a better way of doing this altogether?
|
|
|
|
|
Suppose I have TABLE with the following fields:
Quantity [number]
Price [Number]
Returns [bool]
If Returns = true, then - ([quantity][Price])// negative returns
If Returns = false, then ([quantity][Price]) // positive returns
Question using SQL Server 2005:
Inquiry following his error was in command IIF:
[CODE]
SELECT quantity, Price, Returns, IIF ([Returns] = 0, ([quantity][Price]), (-1)([quantity]*[Price])) As Total
FROM TABLE;
[/CODE]
SQL Syntax Errors Encountered:
The following errors were encountered while parsing the contents of the SQL pane:
Error in list of function arguments: '=' not recognized. Unable to parse query text.
|
|
|
|
|
Wrong forum - this is for C# queries, not SQL. In future use this: Database Discussion Boards - CodeProject[^] or this: http://www.codeproject.com/Questions/ask.aspx[^]
But...try this:
SELECT quantity, Price, [Returns], (quantity * Price) * CASE WHEN [Returns] = 0 THEN 1 ELSE -1 END As Total FROM MyTable; Or if Returns is a BIT column:
SELECT quantity, Price, [Returns], (quantity * Price) * (1 - [Returns] * 2) As Total FROM MyTable;
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Your good example, especially your 2nd query, I do not think writing like this that runs smoothly: (quantity * Price) * (1 - [Returns] * 2) As Total
Your very good example, Thank you very much.
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Below code need to implement to measure the angle in a image. but after stretching the image found the mouse click position and line starting position is not correct.
Line starts some points after the mouse click point. if the image is not stretched no issues
private void pictureBox1_VisibleChanged(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
MouseEventArgs me = (MouseEventArgs)e;
if (me.Button == System.Windows.Forms.MouseButtons.Right)
{
switch (clickProgress)
{
case 1:
pts[2] = pts[0];
pts[1] = pts[0];
clickProgress--;
break;
case 2:
pts[2] = pts[0];
clickProgress--;
break;
case 3:
clickProgress--;
break;
}
}
if (me.Button == System.Windows.Forms.MouseButtons.Left)
{
if (clickProgress < 3)
{
pts[clickProgress] = me.Location;
if (clickProgress == 0)
{
pts[1] = pts[0];
pts[2] = pts[0];
}
clickProgress++;
}
}
updateBitmap();
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (clickProgress > 0 && clickProgress < 3)
pts[clickProgress] = e.Location;
updateBitmap();
}
private void updateBitmap()
{
if (pictureBox1.Image == null)
{
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.Image = bmp;
}
using (Graphics g = Graphics.FromImage(pictureBox1.Image))
{
g.Clear(Color.Black);
if (pic != null)
{
int width = pictureBox1.Width;
int height = pictureBox1.Height;
float scaleW = pictureBox1.Width * 1.0f / width;
float scaleH = pictureBox1.Height * 1.0f / height;
float scale = scaleW;
if (scale > scaleH)
scale = scaleH;
int nw = (int)(scale * width);
int nh = (int)(scale * height);
if (picScaled == null)
{
RectangleF sourceRect = new RectangleF(0, 0, width, height);
RectangleF destinationRect = new RectangleF(0, 0, nw, nh);
picScaled = new Bitmap(nw, nh);
Graphics gi = Graphics.FromImage(picScaled);
gi.DrawImage(
pic,
destinationRect,
sourceRect,
GraphicsUnit.Pixel);
gi.Dispose();
}
{
RectangleF sourceRect = new RectangleF(0, 0, nw, nh);
RectangleF destinationRect = new RectangleF(
pictureBox1.Width / 2 - nw / 2,
pictureBox1.Height / 2 - nh / 2,
nw,
nh);
g.DrawImage(
picScaled,
destinationRect,
sourceRect,
GraphicsUnit.Pixel);
}
}
Pen greenPen = new Pen(Brushes.Green);
greenPen.Width = 3.0F;
Pen redPen = new Pen(Brushes.Red);
redPen.Width = 3.0F;
if (clickProgress > 0)
g.DrawLine(greenPen, pts[0], pts[1]);
if (clickProgress > 1)
g.DrawLine(redPen, pts[0], pts[2]);
redPen.Dispose();
greenPen.Dispose();
}
pictureBox1.Invalidate();
if (clickProgress > 1)
{
Point p0 = new Point(pts[1].X - pts[0].X, pts[1].Y - pts[0].Y);
Point p1 = new Point(pts[2].X - pts[0].X, pts[2].Y - pts[0].Y);
double l0 = (p0.X * p0.X + p0.Y * p0.Y);
double l1 = (p1.X * p1.X + p1.Y * p1.Y);
double d = ((double)p0.X * p1.X + (double)p0.Y * p1.Y) / Math.Sqrt(l0 * l1);
if (d > +1) d = +1;
if (d < -1) d = -1;
if (l0 > 0 && l1 > 0)
label1.Text = (Math.Acos(d) * 180 / Math.PI).ToString("0.0", System.Globalization.CultureInfo.InvariantCulture);
}
else
{
label1.Text = "";
}
}
|
|
|
|
|
Um. What do you suppose PictureBoxSizeMode.StretchImage does?
It takes the image in the Picturebox and "distorts" it to fit the size and shape of the container. That doesn't affect mouse locations within the image, it just affects the image as displayed.
So if you click the mouse on two points in the distorted PictureBox that correspond to the start and end points of a line (on the distorted image) and draw a line (on the underlying image graphics context) using the mouse coordinates it will be drawn as is - the coordinates you draw from and to will not be "mapped" into the distorted image but drawn exactly as you requested on the undistorted image. As a result, they aren't in "the right place" - which is why when you remove StretchImage from the PictureBox it works fine: the coordinates don't change at all, but now they match with the image.
Two options:
1) Don't use StretchImage
2) Convert the mouse location points so they aren't relative to the distorted image. That means looking at the box dimensions, the image dimensions and working out teh X and Y scalign factors you need to apply to "undistort" the click location.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
modified 11-Jun-16 6:58am.
|
|
|
|
|
Hello,
I have a requirement of getting an event when all the Windows are in minimized state. How can I know when all other applications (except mine) are in minimized state using c#?
Please help me.
|
|
|
|
|
As far as I know there is no event that signals this - you can look at each window fairly easily though and enumerate those that are visible: List the currently running desktop windows in C# - C# HelperC# Helper[^] - a couple of small changes there would give you a list of "open" windows. But you'd have to check it periodically yourself.
The other option is a lot more complex, and a lot more fraught with crash-and-burn potential: CBT Hooking. This entails adding a global hook to the system and watching for minimize, restore, and maximize events making their way through. You can do this in C# - though it's not simple - but it's not a trivial task (and I'd back up my PC before I started trying as you can seriously destabilize your system if you get it wrong). Google for "CBT Hooking C#" and you'll find info, if you are brave enough!
[edit]Typo[/edit]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
modified 11-Jun-16 3:27am.
|
|
|
|
|
I am new to c#. The example given by you gives some Titles which are running in system tray and some other titles also, I want window titles which are open but not in minimized state... can you help me where I need to edit the code ?
|
|
|
|
|
Just change the IsWindowVisible part to check if it's minimised with the IsIconic function (Windows)[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Ola Pessoal desde ja eu agradeço o tempo disponibilizado para tentar resolver o meu Problema...
VAMOS AO PROBLEMA
Estou tentando criar um instalador para a minha aplicação C# VS 2012 EM CAMAMADAS
Estou tendo Problemas na minha conexão
essa e a minha string de conexão
Agora no Inno Setup
Defino la no Application name : SIFA
Application versine : 1.0 Next>>
Application destination base folder :
eu escolho custom C:\
Application Files_ Application main executable file Clico em Browse...
e escolho SIFA/GUI/bin/Debugu ou Release/GUI ....... ja tentei tanto com debug quanto com release
depois de clicar e GUI... agora eu clico em ADD FILES e escolho meu banco de dados SQL Compact
Next>> preencho o restante q e mais facil e mais de configuração .....
Beleza instalador criado agora e executo o instalador e instala normalmente...
esta la na pasta C:\SIFA...
mas quando eu executo ele abre Normalmente, mas quando eu clico em algum botão que faz requisição ao banco de dados aparece essa mensagem de erro
OBS: e quando eu executo o programa usando o VISUAL STUDIO mesmo com a conexão apontando para C:\\SIFA\\DataSifa (Imagem 2) ele executa e le o banco de dados sem nem um problema (ele le o banco q foi instalado na pasta c:\SIFA)
Obrigado por sua Atenção.... Espero que tenha ficado Claro a minha duvida
|
|
|
|
|
Unfortunately this is a mainly English language site, and I doubt that many of the subscribers will be able to speak Portuguese
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
This is an English language site, and questions should be posted in English - as should answers.
But from what Google Translate offers, I suspect it's a permissions problem.
I'd strongly suggest that you should store the DB in a more sensible folder: Where should I store my data?[^] may help you there.
Este é um site de idioma Inglês, e as perguntas devem ser afixados em Inglês - como deveria respostas.
Mas do que Google Translate ofertas, eu suspeito que é um problema de permissões.
Eu sugiro fortemente que você deve armazenar o DB em uma pasta mais sensato: Onde devo armazenar meus dados? [ ^ ] pode ajudá-lo lá.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
how can we save image from live view automatically?
|
|
|
|
|
Please read the articl at the top of this page called How to get an answer to your question
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Lots of ways, take your pick. You could write code. You could use an application that has that feature built-in. You could use a camera. Many options.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Live view from what? How are you receiving the data? What code do you currently have? Is this a desktop application?
Please supply more information so that we can begin to offer you some help.
This space for rent
|
|
|
|
|
Dear Friends/Mates,
Please help me to Convert Amibroker AFL to DLL setup file with license manager. I have installed Amibroker software and .net for amibroker but i want to know how to convert Amibroker AFL to DLL setup file with license manager. I am waiting for your help.
Many thanks in advance
|
|
|
|
|
As you have bought AmiBroker, I would expect their online support[^] to be the best source for information like this.
This space for rent
|
|
|
|
|
No, it is a trial version.
|
|
|
|
|
So you're going to buy it then? Or are you looking for help to crack the application?
This space for rent
|
|
|
|
|
Trial or no, it is not part of the Framework. Any decent sales-team would happilly provide you with access to their support team
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi all,
i have a MyPanel type custom control,
MyPanel panel1;
i pass this to another temp variable
MyPanel temp=panel1;
now i remove some control from temp,
but here the remove control also remove from panel1.
please help how can i stop this.
thanks in advance.
|
|
|
|
|