We are given to evaluate:
$$I=\int_0^{\infty} xe^{ax}\cos(x)\,dx$$ where $a<0$
I would write:
$$v(x)=\int xe^{ax}\cos(x)\,dx$$
So that we have the first-order linear inhomogeneous ODE:
$$\d{v}{x}=xe^{ax}\cos(x)$$
Since the homogeneous solution $v_h$ is a constant, we need only find the particular solution, which will have the form:
$$v_p(x)=e^{ax}\left((Ax+B)\cos(x)+(Cx+D)\sin(x)\right)$$
Differentiating w.r.t $x$, and substituting into our ODE, we obtain:
$$\d{v_p}{x}=e^{ax}\left(((aA+C)x+aB+A+D)\cos(x)+((aC-A)x+aD-B+C)\sin(x)\right)=e^{ax}\left((1x+0)\cos(x)+(0x+0)\sin(x)\right)$$
Equating coefficients gives rise to the system:
$$aA+C=1$$
$$aB+A+D=0$$
$$aC-A=0$$
$$aD-B+C=0$$
Solving this system, we obtain:
$$(A,B,C,D)=\left(\frac{a}{a^2+1},\frac{1-a^2}{\left(a^2+1\right)^2},\frac{1}{a^2+1},-\frac{2a}{\left(a^2+1\right)^2}\right)$$
And so, our particular solution may be written:
$$v_p(x)=\frac{e^{ax}}{\left(a^2+1\right)^2}\left((a\left(a^2+1\right)x+1-a^2)\cos(x)+(\left(a^2+1\right)x-2a)\sin(x)\right)$$
Hence, the definite integral in question may be written:
$$I=\frac{1}{\left(a^2+1\right)^2}\lim_{t\to\infty}\left(\left(e^{at}\left((a\left(a^2+1\right)t+1-a^2)\cos(t)+(\left(a^2+1\right)t-2a)\sin(t)\right)\right)-\left(e^{a(0)}\left((a\left(a^2+1\right)(0)+1-a^2)\cos(0)+(\left(a^2+1\right)(0)-2a)\sin(0)\right)\right)\right)$$
$$I=\frac{1}{\left(a^2+1\right)^2}\lim_{t\to\infty}\left(\left(e^{at}\left((a\left(a^2+1\right)t+1-a^2)\cos(t)+(\left(a^2+1\right)t-2a)\sin(t)\right)\right)-\left((1-a^2)\right)\right)=\frac{a^2-1}{\left(a^2+1\right)^2}$$